Spring Manufacturing Exception Handling Versus Development

I use Spring MVC and I am handling Exception in the first order described here: http://www.javacodegeeks.com/2013/06/spring-mvc-error-handling-flow.html

which basically puts the following code in web.xml

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/uncaughtException</location>
</error-page> 

Now I need to do 2 types of views for production and development. For development, I will print full glass; for production, I would say something like: "Something is bad, try again later." I need suggestions on the distinction between production and development. I use apache maven to compile, and there is a flag β€œ-Dbuild.type = dev” which says it is a compilation of dev.

Any help would be appreciated, thanks.

+4
source share
2 answers

Take a look at the spring abstraction Environmentdescribed at http://spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/

+1
source

You can put the variable in your maven development and development profiles and map it to java bean.

Here is the profile bit

<profiles>
    <profile>
        <id>prod</id>
        <properties>
            <system.serverType>PROD</system.serverType>
        </properties>
    </profile>
    <profile>
        <id>qa</id>
        <properties>
            <system.serverType>QA</system.serverType>
        </properties>
    </profile>
</profiles>

Then in /src/main/resources/applicationContext.xml

<bean id="system" class="com.company.project.System" 
    p:serverType="${system.serverType}"
/>

Then it maps the build profile to your java class.

public class System {
    public static enum ServerType {PROD, QA, DEV} 

    private ServerType serverType;
    public void setServerType(ServerType serverType) {
        this.serverType = serverType;
    }
    public ServerType getServerType() {
        return serverType;
    }

    public boolean isProduction() {
        return serverType == ServerType.PROD;
    }
}
0
source

All Articles