日期:2014-05-19  浏览次数:20885 次

struts2.21+spring2.5+hibernate3.2,求解依赖注入空指针(来者有分)
-------------------Struts---------------------
Java code

<?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE struts PUBLIC
      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
      "http://struts.apache.org/dtds/struts-2.0.dtd">
  <struts>
        
      <constant name="struts.objectFactory" value="spring" />
      <package name="struts2"  extends="struts-default">
          <global-results>
                  <result name="error">/login.jsp</result>
          </global-results>
          <action name="login" class="LoginAction" method="doLogin">
                      <result name="success">/index.jsp</result>
                       <result name="error">/login.jsp</result>
          </action>
      </package>

  </struts>




-------------------------applicationContext.xml---------------------------
Java code

<bean id="UserBasicInfoDAO" class="model.UserBasicInfoDAO">
        <property name="sessionFactory">
            <ref bean="sf" />
        </property>
    </bean>
    
    <bean id="LoginImpl" class="impl.LoginImpl" >
        <property name="userBasicInfoDAO" ref="UserBasicInfoDAO" />
    </bean>
    
    <bean id="LoginAction" class="action.LoginAction" >
        <property name="loginImpl" ref="LoginImpl" />
    </bean>



-----------------------------------web.xml----------------------
Java code

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    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-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
     <filter>
        <filter-name>ssh2</filter-name>
        <filter-class>
             org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
            <!-- org.apache.struts2.dispatcher.FilterDispatcher-->
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ssh2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    

</web-app>

----------------------------LoginAction----------------------------
package action;

import model.UserBasicInfo;
import impl.LoginImpl;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends