我检查了很多地方,但无法在我的配置中找到错误。请帮忙。
面孔-config.xml
<managed-bean>
<managed-bean-name>notificationServlet</managed-bean-name>
<managed-bean-class>com.comviva.workflow.ui.notification.NotificationServlet</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>notificationDao</property-name>
<value>#{notificationDaoService}</value>
</managed-property>
</managed-bean>
应用程序上下文.xml
<bean id="notificationDao" class="com.comviva.workflow.ui.dao.NotificationDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="notificationDaoService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="myTransactionManager" />
</property>
<property name="target">
<ref local="notificationDao" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_NEVER</prop>
</props>
</property>
</bean>
Java 类
@SessionScoped
@ManagedBean(name = "notificationServlet")
public class NotificationServlet extends HttpServlet
{
private static final long serialVersionUID = -3905661117247475401L;
@ManagedProperty("#{notificationDao}")
NotificationDao notificationDao;
}
我收到 NullPointerException。请建议我缺少什么。
编辑:-
2013-08-13 21:22:34,407 INFO (NotificationServlet.java:43) notificationDao :: null
2013-08-13 21:22:34,407 ERROR (NotificationServlet.java:60) Exception ::
java.lang.NullPointerException
at com.comviva.workflow.ui.notification.NotificationServlet.doPost(NotificationServlet.java:44)
at com.comviva.workflow.ui.notification.NotificationServlet.doGet(NotificationServlet.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
编辑 :-
我不太擅长这些技术,但据我所知,我使用这些技术是因为——
Spring - 创建 bean 对象以防止每次类访问时创建多个对象。
Servlet - 我必须像“通知”一样实现 facebook,所以我在 JSP 页面中“计时(轮询)” servlet URL 以检查是否有任何值更新。
JSF - 我用它来创建 UI。我是 JSF 的新手,所以我不知道如何用它来实现 Spring。所以我问我是否遗漏了什么。
我在我的班上有 setter/getter 方法。我只是没有显示它以节省空间。(如果混淆了假设,请道歉。)
解决方案 :-
我从 Java 类中删除了 faces-config.xml 和 JSF 注释中的两个 bean。我正在通过使用以下方法在 java 类本身中捕获 dao bean:-
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
notificationDao = (NotificationDao)context.getBean("notificationDao");
感谢您的建议。