Good evening all,
I've been working on a JSF 2 app with Spring 3.1.1 for the last few weeks.
Somewhere along the line, a strange problem started occurring when upon redeploy or Tomcat (6 or 7) restart, the JSF managed backing bean doesn't get its required Spring beans injected.
The JSF beans are annotated (rather than using the faces-config.xml file). The JSF bean in question is the backing bean for the first page of the webapp.
It is annotated as
.Code:@ManagedBean(name = "indexBackingBean") @SessionScoped
The Spring bean is defined in the applicationContext-beans.xml file. In my JSF bean, it's annotated asSometimes, when the web app starts up, everything is fine but sometimes, and even after repeated redeploys and Tomcat restarts, the managed property in my JSF backing bean is null and there is no sign of Spring in the resulting NullPointerException stacktrace.Code:@ManagedProperty(value="#{mainService}")
Below are relevant snippets of the config files (class names, package names and noise removed).
In the web.xml file I have:
faces-config.xmlCode:<?xml version="1.0"?> <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_2_5.xsd" id="myproject" metadata-complete="false" version="2.5"> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext-beans.xml /WEB-INF/applicationContext-persistence.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value>/WEB-INF/faces-config.xml</param-value> </context-param> <!-- Faces Servlet --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> ...
applicationContext-beans.xmlCode:<?xml version="1.0"?> <faces-config xmlns="http://java.sun.com/xml/ns/javaee" 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_5.xsd" version="2.5"> <application> <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver> </application> </faces-config>
Any suggestions? It has started doing it on the Linux development server as well as the Windows PC I've been working on so it doesn't appear to be environmental.Code:<?xml version="1.0" encoding="UTF-8"?> <!-- - Application context definition for TCL Wholesale EBill site on Hibernate. --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <context:component-scan base-package="com.mypackage" /> <context:annotation-config /> <bean id="mainService" class="com.mypackage.MainService" scope="singleton"> </bean> </beans>


Reply With Quote
).