2013-12-19 59 views
4

我使用Spring MVC和我在这里的处理描述的第一种方式的异常:http://www.javacodegeeks.com/2013/06/spring-mvc-error-handling-flow.html春季异常HANDELING生产VS发展

它基本上把下面的代码在web.xml

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

现在,我需要为生产和开发制作两种类型的视图。对于开发,我会打印完整的堆栈跟踪,用于生产,我会这样说:“发生了什么不好的事情,请稍后再试。”我需要建议来区分生产和发展。我使用Apache Maven进行编译,并且有一个标志“-Dbuild.type = dev”,表示它是一个开发编译。

任何帮助将不胜感激,谢谢。

回答

0

描述你可以把一个变量在生产和发展的Maven配置文件和其映射到一个Java bean。

这里是简介位

<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> 

然后在/src/main/resources/applicationContext.xml

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

这则映射生成配置文件到您的Java类。

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; 
    } 
} 
+1

我可以指定它是生产还是开发,当我编译? – faisal