当前位置: 代码迷 >> Java Web开发 >> Spring 没法注入
  详细解决方案

Spring 没法注入

热度:6740   发布时间:2013-02-25 21:15:57.0
Spring 无法注入
一个简单的登陆页面,登陆的时候抛出异常。

严重: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at com.grace.studentGradeManage.action.StudentAction.loginAction(StudentAction.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Thread.java:619)
web.xml 配置:
[code=Java][/code] <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
  </context-param>
  
  <listener> 

  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 

  </listener> 

applicationContext.xml配置:

XML code
    <bean id="studentDao" class="com.grace.studentGradeManage.dao.StudentDao">        <property name="sessionFactory">            <ref bean="sessionFactory"/>        </property>    </bean>            <bean id="studentService" class="com.grace.studentGradeManage.service.StudentService">        <property name="studentDao">             <ref bean="studentDao"/>            </property>    </bean>        <bean name="/studentAction" class="com.grace.studentGradeManage.action.StudentAction">        <property name="studentService">            <ref bean="studentService"/>        </property>        </bean>


------解决方案--------------------------------------------------------
你把/WEB-INF/classes/applicationContext.xml改为classpath:applicationContext.xml试一试,还有就是你得测试下你的studentDAO是否为null,再判断是否注入,到底是没有注入还是你的action自己写得有问题,里面是有有set方法!!。
------解决方案--------------------------------------------------------
  相关解决方案