繁体   English   中英

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

[英]Make deployment fail with customized error in Glassfish 3.1

通过在@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!");
}

我认为“打破”部署并抛出异常的方法是使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM