@PostConstruct annotation not called on JBoss 6.0
mrkspfeiffer Apr 1, 2011 4:40 AMAt first, I already know the thread http://community.jboss.org/thread/150609 and tried out all suggested solutions:
Added JBossScanningInjectionProvider to web.xml
[code]
<context-param>
<param-name>com.sun.faces.injectionProvider</param-name>
<param-value>org.jboss.web.jsf.integration.injection.JBossScanningInjectionProvider</param-value>
</context-param>
[/code]
Copied jboss-faces.jar from \jboss-6.0.0.Final\server\default\deployers\jsf.deployer\Mojarra-2.0\jsf-libs into WEB-INF/libs
Conclusion is that @PostConstruct still not get called.
Im using following:
- jboss-6.0.0.Final
- Java 6
- JSF
- jsf-api 2.0.3
- jsf-impl 2.0.3
- javaee-api
- [jpa 2.0 (not included yet)]
Projects:
EAR project
Service project (includes @Stateless EJBs)
ServiceClient project (includes @Local interfaces for service project)
Web project
Snippets:
Service
[code]
@Stateless
public class TestService implements TestServiceLocal {
@Override
public String doTest() {
// TODO Auto-generated method stub
return "test string";
}
[/code]
Service interface
[code]
@Local
public interface TestServiceLocal {
public abstract String doTest();
}
[/code]
}
Managed bean
[code]
public class TestBean {
@EJB
private TestServiceLocal testService;
private String s;
@PostConstruct
public void init() {
s= testService.doTest();
}
[/code]
faces-config.xml
[code]
<?xml version="1.0"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" 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-facesconfig_2_0.xsd">
<managed-bean>
<managed-bean-name>testBean</managed-bean-name>
<managed-bean-class>com.xx.web.test.TestBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
[/code]
web.xml
[code]
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Web</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>com.sun.faces.application.WebappLifecycleListener</listener-class>
</listener>
<context-param>
<param-name>com.sun.faces.injectionProvider</param-name>
<param-value>org.jboss.web.jsf.integration.injection.JBossScanningInjectionProvider</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>hello.xhtml</welcome-file>
</welcome-file-list>
</web-app>
[/code]
WEB-INF/libs contains:
- common-annotation.jar
- commons-beanutils.jar
- commons-collections.jar
- commons-digester.jar
- commons-logging.jar
- jstl.jar
- standard.jar
- jboss-faces.jar
[/code]