[英]@PostConstruct Wrong deploy in GlassFish
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.