问题是这样, 在applicationContext.xml的配置里,
配置和测试dataSource和sessionFactory都正常,
都能拿到Connection和session,(我这里用的是DriverManagerDataSource),
直到我配置好txAdvice和txManger测试都正常,到最后加上aop:config的时候就报错了!
所以我认为问题出在下面的aop:config的配置上, 除非删掉它无论我怎么配置它都报错!
无奈大家帮我看看吧, 第一次问问问题分都给你们吧, 也没多少分其实~~
上配置:
<context:property-placeholder location="jdbc.properties" />
<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<aop:config>
<aop:pointcut expression="execution(* cn.tboa.dao..*.*(..))" id="daoMethod" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethod" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delte*" propagation="REQUIRED" />
<tx:method name="merge*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
最后再声明一下, 在添加aop:config之前,所有配置都没问题的!
我有这样的一个包结构:
cn.tboa.dao
cn.tboa.dao.impl
错误信息如下:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'txManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txManager' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)