spring 属性注入问题,为什么生成的对象总是为空?
[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]
麻烦大家帮我分析一下到底是怎么回事,谢谢了!