简体   繁体   English

@PostConstruct 在 GlassFish 中部署错误

[英]@PostConstruct Wrong deploy in GlassFish

  • My project is based in Spring 4.2.3.RELEASE我的项目基于 Spring 4.2.3.RELEASE
  • Before a use Tomcat, but last migration project has one problem with ClassLoader, then change Tomcat 8 for GlassFish 4.1!之前用Tomcat,但是上次迁移项目ClassLoader有问题,于是把Tomcat 8换成GlassFish 4.1!
  • In project has one @Component("i18N")在项目中有一个@Component("i18N")
  • in my Object call i18N has one method在我的对象调用中i18N有一个方法
  • But i'm to deploy in GlassFish the file site-1.3.0.0.war但是我要在 GlassFish 中部署文件site-1.3.0.0.war
  • Has put a wrong error已经放错了错误
  • In other project has same problem, but i'm dont have time to solve this problem, at now i'm need solved this.在其他项目中也有同样的问题,但我没有时间解决这个问题,现在我需要解决这个问题。

Error occurred during deployment: Exception while deploying the app 
[site-1.3.0.0] : The lifecycle method [init] must not throw a checked exception. Related annotation information: annotation 
[@javax.annotation.PostConstruct()] on annotated element [public void com.sys.resolver.SysResourceBundleRead.init() throws java.lang.IllegalAccessException,java.lang.InstantiationException,java.io.IOException,org.apache.taglibs.standard.lang.jstl.ELException] of type 
[METHOD]. Please see server.log for more details.

add the method class添加方法类

** @PostConstruct public void init() throws Exception{ ** @PostConstruct public void init() 抛出异常{

} ** } **

As the error message says, a method with @PostConstruct must not throw checked Exceptions.正如错误消息所说,带有@PostConstruct的方法不得抛出已检查的异常。

So remove throws Exception from your method and catch it in the method body:因此,从您的方法中删除throws Exception并在方法主体中捕获它:

@PostConstruct
public void init() {

   try {
         // bla
   } catch (Exception x) {
        // do something
   }

}

Here I already made work around that worked in my case. 在这里,我已经解决了在我的情况下有效的工作。

You can solve this issue first by adding a web.xml with metadata-complete="true".您可以首先通过添加带有 metadata-complete="true" 的 web.xml 来解决此问题。 Next you will want to make sure your context are in the Web root Directory /WEB-INF/.接下来,您需要确保您的上下文位于 Web 根目录 /WEB-INF/ 中。

With this glassfish can load all @PostConstructSpring dependencies.使用此 glassfish 可以加载所有 @PostConstructSpring 依赖项。

I solved by adding the metadata-complete="true" in the web.xml like:我通过在 web.xml 中添加metadata-complete="true"来解决,例如:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" metadata-complete="true">

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

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