维护一个老项目,在本地调试,想手动加载spring配置文件,但属性总是不能成功注入,请各位高手帮忙看一看,一下是配置文件
配置文件1:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byName" default-lazy-init="true">
<!-- 属性文件读入 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:config/jdbc.properties</value>
</list>
</property>
</bean>
<!-- 支持 @Transactional 标记 -->
<tx:annotation-driven/>
<!-- 支持 @AspectJ 标记-->
<aop:aspectj-autoproxy/>
<!-- 以AspectJ方式 定义 AOP -->
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.wind.managerImpl.*Manager*.*(..))"
advice-ref="txAdvice"/>
</aop:config>
<!-- 基本事务定义,使用transactionManager作事务管理,默认get*方法的事务为readonly,其余方法按默认设置.
默认的设置请参考Spring文档事务一章. -->
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
配置文件2:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<!-- 数据源定义,使用Apache DBCP 连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialSize" value="50"></property>
<property name="maxActive" value="100"></property>
<property name="maxWait" value="60000"></property>
<property name="removeAbandonedTimeout" value="180"></property>
<property name="removeAbandoned" value="true"></property>
</bean>
<!--Hibernate SessionFatory--><!-- org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingDirectoryLocations">
<list>
<value>classpath*:/com/wind/mapping/</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
</props>
</property>
</bean>
<!--Hibernate TransactionManager-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
配置文件3:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<!-- 数据访问接口dao -->
<bean id="tbSqlDao" class="com.wind.daoImpl.TbSqlDaoImpl" />
<bean id="tbCdqResultfourDao" class="com.wind.daoImpl.TbCdqResultfourDaoImpl" />
<bean id="tbFarmInfoDao" class="com.wind.daoImpl.TbFarmInfoDaoImpl" />
<bean id="tbLogInfoDao" class="com.wind.daoImpl.TbLogInfoDaoImpl" />
<bean id="tbNwpDao" class="com.wind.daoImpl.TbNwpDaoImpl" />
<bean id="tbResultMeanDao" class="com.wind.daoImpl.TbResultMeanDaoImpl" />
<bean id="tbSysInfoDao" class="com.wind.daoImpl.TbSysInfoDaoImpl" />
<bean id="tbSysrunMonitoringDao" class="com.wind.daoImpl.TbSysrunMonitoringDaoImpl" />
<bean id="tbUserDao" class="com.wind.daoImpl.TbUserDaoImpl" />
<bean id="tbUserPrivilegeDao" class="com.wind.daoImpl.TbUserPrivilegeDaoImpl" />
<!-- <bean id="tbWindTowerDao" class="com.wind.daoImpl.TbWindTowerDaoImpl" /> -->
<bean id="tbFiveWindTowerDao" class="com.wind.daoImpl.TbFiveWindTowerDaoImpl"/>
<bean id="jrFiveGfQxzDao" class="com.wind.daoImpl.JrFiveGfQxzDaoImpl"/>
<!-- end -->
<!-- 业务类 -->
<bean id="tbLineManager" class="com.wind.managerImpl.TbLineManagerImpl"/>
<bean id="tbUserManager" class="com.wind.managerImpl.TbUserManagerImpl"/>
<bean id="tbConnectorManager" class="com.wind.managerImpl.TbConnectorManagerImpl"/>
配置文件4:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<!-- 定时调度 接口程序 -->
<!-- <import resource="classpath:com/wind/connector/quartz/applicationContext-quartz.xml"/> -->
在运行的类中,我手动加载这四个配置文件如下:
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext(new String[]{"spring/dataAccessContext-hibernate.xml",
"spring/applicationContext-components.xml",
"spring/applicationContext.xml",
"spring/serviceContext.xml"});
但实际运行当中,得到的tbConnectorManager始终为null,该类中,tbConnectorManager的set方法是有的,请各位高手帮忙,谢谢了!