[size=14px][size=12px]在ssh2项目整合过程中遇到一个问题:
java 代码:
public class LoginAction extends ActionSupport {
         private ILoginManager iLoginManager;
private Customer customer;
private String username;
private String password; public void setILoginManager(ILoginManager loginManager) {
iLoginManager = loginManager;
} public ILoginManager getILoginManager() {
return iLoginManager;
}
       
//用户登录
public String customerLogin() throws Exception { System.out.println("username = " + username);
System.out.println("password = " + password);
System.out.println("iLoginManager = " + iLoginManager); Customer customer = new Customer();
customer.setUsername(username);
customer.setPassword(password); if (iLoginManager.login(customer)) {
return "success";
}
if(username != null && password != null){
return "success";
} //PropertyConfigurator.configure("log4j.properties");
//logger.debug("111111111111111");
return "loginfail";
}
 
}
上面标红的地方就是提示 iLoginManager 为空spring 配置文件代码:applicationContext-action.xml<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/oxm
    http://www.springframework.org/schema/oxm/spring-oxm-2.5.xsd"> <bean id="userLogin" class="com.z2sci.soa.web.action.LoginAction">
<property name="ILoginManager" ref="ILoginManager" />
</bean></beans>applicationContext-bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/oxm
    http://www.springframework.org/schema/oxm/spring-oxm-2.5.xsd">

<bean id="iLoginDao" class="com.z2sci.soa.dao.impl.LoginDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="ILoginManager" class="com.z2sci.soa.manager.impl.LoginManagerImpl">
<property name="iLoginDao" ref="iLoginDao" />
</bean>
</beans>applicationContext-commons.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 配置SessionFactory  -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean> <!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean> <!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice> <!-- 配置哪些类哪些方法使用事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod"
expression="execution(* com.z2sci.soa.dao.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="allManagerMethod" />
</aop:config>
</beans>
 
[/size][/size]麻烦大家帮我分析一下到底是怎么回事,谢谢了!

解决方案 »

  1.   

    private ILoginManager iLoginManager;

    <bean id="userLogin" class="com.z2sci.soa.web.action.LoginAction">
    <property name="ILoginManager" ref="ILoginManager" />
    iLoginManager与ILoginManager名字不一致?!你试一下!!
      

  2.   

    <bean id="userLogin" class="com.z2sci.soa.web.action.LoginAction">
    <property name="iLoginManager" ref="ILoginManager" />
    </bean>
      

  3.   

    你struts2的配置文件是不是<action name="userLogin" method="add" class="userLogin" >这样写的嘛,action的id必须要在spring中拿
      

  4.   

     private ILoginManager iLoginManager;属性第二个字母不要大写。
      

  5.   

    <bean id="ILoginManager" class="com.z2sci.soa.manager.impl.LoginManagerImpl">
    <property name="iLoginDao" ref="iLoginDao" />
    </bean>

    你这边配置的跟你类中的属性名不一致。
      

  6.   

    action id 必须在spring 中拿 什么意思?能详细说说吗? 
      

  7.   

    我之前配置的是 “iLoginManager”,因为在LoginAction中生成对象iLoginManager 为空我才该成“ILoginManager”的,修改了之后还是iLoginManager 对象为空
      

  8.   

    public void setILoginManager(ILoginManager loginManager) {
    iLoginManager = loginManager;
    }
    这个你用自动的生成一下seter吧!可能会好点!
      

  9.   

    属性第一个和第二个字母大写的话,生成的get和set方法是错的,不信你去看下好了