Spring2.5-------
applicationContext.xml文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName" default-lazy-init="true">
<!-- SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <!-- 事务控制 --> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" rollback-for="Exception" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- 去掉这个不出错,但事务不提交 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="userServiceOperation" expression="execution(* com.jhkj.pt.mk..*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="userServiceOperation" />
</aop:config>
<!--      -->
<bean id="PtMkDAO" class="com.jhkj.pt.mk.PtMkDAO">
<property name="hibernateTemplate">
<ref bean="hibernateTemplate" />
</property>
</bean>
</beans>
问题是
如果配置<aop:config ... ,在Dao中不能得到hibernateTemplate,是null
如果去掉<aop:config ... ,不提交事务
怎么回事呀,弄几天了,帮帮我哦

解决方案 »

  1.   

    问题解决了
    1.----------
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="false">
    <property name="driverClassName">
    <value>net.sourceforge.jtds.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:jtds:sqlserver://zh:1433/ax</value>
    </property>
    <property name="username">
    <value>sa</value>
    </property>
    <property name="password">
    <value>sa</value>
    </property>
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    <property name="mappingResources">//省略---------2.------------
    <aop:config proxy-target-class="true"> 
    <aop:pointcut id="userServiceOperation" expression="execution(* com.jhkj.pt..*..*DAO.save*())" /> 
    <aop:advisor advice-ref="txAdvice" pointcut-ref="userServiceOperation" /> 
    </aop:config> 疑惑:::::
    至于为什么不能用
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation">
    <value>classpath:hibernate.cfg.xml</value>
    </property>
    </bean>
    我也不知道
    哎,没人指点呀
    发了n个贴也解决不了问题,55555555555