EAR打包环境下JAR中JSF ManagedBean的@PostConstruct未触发问题
问题:EAR环境下JAR中ManagedBean的@PostConstruct未触发
我知道类似问题已经有过讨论,但我的场景有点特殊,想请教大家:我把包含ManagedBean的JAR和需要解析JAR内视图资源并调用该Bean的WAR,一起打包在了EAR里,结果出现了Bean的@PostConstruct方法未触发的问题。
我的运行环境
- Weblogic 12c
- JSF版本:
jsf_2.0.0.0_2-1-20.jar(由Weblogic自带)
JAR的目录结构与配置
JAR里的faces-config.xml放置位置是正确的,完整目录结构如下:
0 Mon May 14 12:20:08 CST 2018 META-INF/ 125 Mon May 14 12:20:06 CST 2018 META-INF/MANIFEST.MF 0 Mon May 14 12:20:06 CST 2018 META-INF/resources/ 0 Mon May 14 12:20:06 CST 2018 gt/ 0 Mon May 14 12:20:06 CST 2018 gt/com/ 0 Mon May 14 12:20:06 CST 2018 gt/com/leta/ 0 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/ 0 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/errorhandlers/ 0 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/pojos/ 0 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/utilities/ 4460 Mon May 14 12:20:06 CST 2018 META-INF/resources/menu.xhtml 4403 Mon May 14 12:20:06 CST 2018 META-INF/resources/login.xhtml 338 Mon May 14 12:20:06 CST 2018 META-INF/faces-config.xml 922 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/errorhandlers/CustomExceptionHandlerFactorySisleta.class 4381 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/errorhandlers/CustomExceptionHandlerSisLeta.class 15480 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/utilities/FunctionsSecurity.class 1146 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/utilities/FaceletsResourceResolver.class 13435 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/utilities/Menu.class 4158 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/utilities/FilterApp.class 2746 Mon May 14 12:20:06 CST 2018 gt/com/leta/security/utilities/SessionListener.class 0 Mon May 14 12:20:08 CST 2018 META-INF/maven/ 0 Mon May 14 12:20:08 CST 2018 META-INF/maven/gt.com.leta/ 0 Mon May 14 12:20:08 CST 2018 META-INF/maven/gt.com.leta/Security/ 5030 Mon May 14 10:57:24 CST 2018 META-INF/maven/gt.com.leta/Security/pom.xml 105 Mon May 14 12:20:08 CST 2018 META-INF/maven/gt.com.leta/Security/pom.properties
对应的ManagedBean代码
这个Bean的@PostConstruct注解标注的init()方法完全没有触发,代码如下:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package gt.com.late.security.; import java.io.IOException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.annotation.PostConstruct; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletRequest; import org.primefaces.context.RequestContext; import org.primefaces.model.menu.DefaultMenuItem; import org.primefaces.model.menu.DefaultMenuModel; import org.primefaces.model.menu.DefaultSubMenu; /** * * @author */ @ManagedBean(name="menu", eager = true) @SessionScoped public class Menu { private String ... private String .... /** * Creates a new instance of Menu */ public Menu() { } @PostConstruct public void init(){ /* This doesn't trigger */ } }
WAR的资源解析配置
WAR是通过FaceletsResourceResolver来获取JAR内的视图资源的,这部分功能运行正常,配置如下:
<context-param> <param-name>facelets.RESOURCE_RESOLVER</param-name> <param-value>com.example.FaceletsResourceResolver</param-value> </context-param>
想请教下,在EAR环境下处理这种JAR+WAR的组合场景,是不是存在什么特殊的差异导致@PostConstruct方法没触发?
内容的提问来源于stack exchange,提问作者HAAO
相关产品推荐
相关产品推荐

