Java Spring声明性事务使用AOP和hibernate,仍然使用默认事务策略
我正在尝试使用AOP和hibernate实现一个使用Spring事务管理的示例应用程序。 下面是我的配置文件Java Spring声明性事务使用AOP和hibernate,仍然使用默认事务策略,java,spring,Java,Spring,我正在尝试使用AOP和hibernate实现一个使用Spring事务管理的示例应用程序。 下面是我的配置文件 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/conte
<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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd ">
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- Beans Declaration -->
<bean id="userDAO" class="com.wjb.daoimpl.UserDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="userOperation" expression="execution(* com.wjb.daoimpl.UserDAOImpl.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="userOperation"/>
</aop:config>
<!-- Database Configuration -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://10.12.30.180:4568/finitedb" />
<property name="username" value="finiteuser" />
<property name="password" value="finiteuser" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="annotatedClasses">
<list>
<value>com.wjb.user.model.User1</value>
</list>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
</beans>
当我运行应用程序时,我在日志中看到下面几行,这表明我的spring事务没有被调用
2013年2月27日上午11:00:20 org.hibernate.dialen.dialen信息:
HH000400:使用方言:org.hibernate.dialogue.PostgreSqlDialogue
2013年11月27日上午11:00:20
org.hibernate.engine.jdbc.internal.LobCreatorBuilder
UseContextAllobCreation信息:HH000423:禁用上下文LOB
创建为JDBC驱动程序报告JDBC版本[3]少于2月27日4日,
2013年11:00:20上午
org.hibernate.engine.transaction.internal.TransactionFactoryInitiator
initiateService信息:HH000399:使用默认事务策略
(直接JDBC交易)2013年2月27日上午11:00:20
org.hibernate.hql.internal.ast.astQueryTranslator工厂信息:
HH000397:使用ASTQueryTranslatorFactory
我遗漏了什么吗?请帮助来自vmoksha的Sunilkumar 将此行插入到applicationcontext.xml中
并且在你的课堂上也加入注释 @交易
public class UserDAOImpl {
Session session;
SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory = sessionFactory;
session = this.sessionFactory.openSession();
}
public void addUser(User1 user) {
session.save(user);
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
}