在Glassfish 3.1中使部署失败并出现自定义错误

时间:2015-06-12 06:21:54

标签: java java-ee glassfish java-ee-6 glassfish-3

通过在@Startup标记的bean中的@PostConstruct标记方法中抛出异常,我当前能够在Glassfish 3.1服务器上部署应用程序时发出警告消息。但是,它仍然部署(因此它位于应用程序列表中),并且错误消息是一个相当模糊的消息,而不是与异常一起给出的消息。

我希望完全部署失败,并提供适当的消息,以指出出现了什么问题。如果没有自定义Glassfish服务器,这可以从标准Ja​​va EE中完成吗?如果是这样,怎么样?

当前设置是一个域应用服务器和两个实例。

当前给定的消息如下

Warning Command succeeded with Warning
"http://localhost:4848/management/domain/applications/application/applicationname" created successfully. WARNING: Command _deploy did not complete successfully on server instance instance1: remote failure: Failed to load the application on instance instance1. The application will not run properly. Please fix your application and redeploy. Exception while shutting down application container : java.lang.NullPointerException. Please see server.log for more details. WARNING: Command _deploy did not complete successfully on server instance instance1: remote failure: Failed to load the application on instance instance1. The application will not run properly. Please fix your application and redeploy. Exception while shutting down application container : java.lang.NullPointerException. Please see server.log for more details.

@PostConstruct

中使用的代码示例
@PostConstruct
public void init() throws ExceptionInInitializerError {
    throw new ExceptionInInitializerError("Don't deploy!");
}

也适用于

@PostConstruct
public void init() throws Exception {
    throw new Exception("Don't deploy!");
}

在RuntimeException

的情况下也是如此
@PostConstruct
public void init() {
    throw new RuntimeException("Don't deploy!");
}

1 个答案:

答案 0 :(得分:2)

我认为通往"打破"部署并抛出异常是使用JavaEE SPI扩展。

她的简单教程如何做到:

http://blog.eisele.net/2010/01/jsr-299-cdi-portable-extensions.html

我正在使用这个,但它用于glassfish4

http://www.byteslounge.com/tutorials/java-ee-cdi-extension-example

相关问题