ApplicationContext.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: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/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd" default-lazy-init="true"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=lin.com)(PORT=2000)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=s1.lin.com)))" /> <property name="username" value="user" /> <property name="password" value="pwd" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <!-- jdbc template --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <constructor-arg> <ref bean="dataSource" /> </constructor-arg> </bean> <!-- Dao --> <bean id="abstractDaoLocator" class="lin.dao.AbstractDaoLocator" abstract="true"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="exchangeDaoLocator" class="lin.dao.impl.ExchangeDaoLocator" parent="abstractDaoLocator"> </bean> <bean id="testDaoLocator" class="lin.dao.impl.TestDaoLocator" parent="abstractDaoLocator"> </bean> <!-- Transaction Control --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> <property name="defaultTimeout" value="15"/> <property name="rollbackOnCommitFailure" value="true"/> </bean> <aop:config> <aop:advisor pointcut="execution(* lin.DbTest..*(..))" advice-ref="requiresNewTxAdvice" /> </aop:config> <tx:advice id="requiresNewTxAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRES_NEW" /> </tx:attributes> </tx:advice> </beans>
hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> <!-- This XML holds the hibernate configuration information. RTP uses annotations, so we do not need to maintain hibernate mapping xml files. Please add an entry for every domain object here. --> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database Settings --> <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="show_sql">false</property> <!-- JDBC Settings --> <property name="jdbc.use_streams_for_binary">true</property> <property name="max_fetch_depth">1</property> <property name="hibernate.transaction.auto_close_session">true</property> <property name="hibernate.transaction.flush_before_completion">true</property> <mapping class="lin.domain.Exchange" /> <mapping class="lin.domain.Test" /> </session-factory> </hibernate-configuration>
相关推荐
<tx:advice id="txAdvice" transaction-manager="transactionManager"> *" propagation="REQUIRED" rollback-for="Exception"/> *" propagation="REQUIRED" rollback-for="Exception"/> *" propagation=...
<tx:advice id="txAdvice" transaction-manager="transactionManager"> *" propagation="REQUIRED"/> ``` 以上配置表明,所有在com.example.service包及其子包下的方法都将被包含在默认的REQUIRED事务传播...
10.2.6. Quick-start Spring CLI Example 10.3. Upgrading from an Earlier Version of Spring Boot 11. Developing Your First Spring Boot Application 11.1. Creating the POM 11.2. Adding Classpath ...
<tx:advice id="txAdvice" transaction-manager="transactionManager"> *" propagation="REQUIRED"/> <bean id="transactionManager" class="org.springframework.jdbc.datasource....
<tx:annotation-driven transaction-manager="transactionManager"/> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> ``` 总的来说,Spring与...
<tx:annotation-driven transaction-manager="transactionManager"/> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> ``` 3. **启用组件扫描...
<tx:annotation-driven transaction-manager="transactionManager"/> ``` 7. **mybatis-config.xml文件**:配置MyBatis的基本参数。 ```xml <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config...
<tx:annotation-driven transaction-manager="transactionManager"/> ``` 这样,带有@Transactional注解的类或方法将会自动地被Spring事务代理处理。 3. **编程式事务管理** 编程式事务管理允许在代码中显式地...
<tx:annotation-driven transaction-manager="transactionManager"/> ``` **2. dispatcher-servlet.xml**: - 配置Spring MVC的相关组件。 - 示例配置: ```xml <beans xmlns="http://www.springframework...
<tx:annotation-driven transaction-manager="transactionManager"/> <context:component-scan base-package="com.example"/> ``` 最后,我们可以在服务类中通过@Autowired注解注入Mapper接口,直接调用其方法执行...
<tx:annotation-driven transaction-manager="transactionManager"/> ``` 在项目中创建Mapper接口,例如`UserMapper.java`,并定义对应的方法: ```java package com.example.demo.mapper; import org.apache....
<tx:advice id="txAdvice" transaction-manager="transactionManager"> *" propagation="REQUIRED"/> *" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/> *" propagation="REQUIRED" ...
这些可以在`<tx:advice>`标签的`transaction-manager`属性中指定。 3. **创建事务通知**: 事务通知定义了哪些方法应该在事务内执行。使用`<tx:method>`标签,可以指定匹配的方法名、传播行为、读写性质、隔离级别...
<tx:advice id="transactionAdvice" transaction-manager="transactionManager"> *" propagation="REQUIRED"/> ``` 这里,`*`表示所有方法都将在`REQUIRED`事务传播策略下运行,即如果当前没有事务,则...
<tx:advice id="txAdvice" transaction-manager="transactionManager"> *" propagation="REQUIRED"/> (* com.example.service.UserService.*(..))"/> ``` 这段配置表示,对于`UserService`类中...
<tx:annotation-driven transaction-manager="transactionManager"/> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> ``` 最后,资源加载是 Spring...
<tx:annotation-driven transaction-manager="transactionManager"/> ``` 8. **使用示例**:在业务逻辑类中,我们可以通过@Autowired注解注入SqlSessionTemplate或Mapper接口,然后在方法中调用相应的方法进行...
<tx:advice id="transactionAdvice" transaction-manager="transactionManager"> *" propagation="REQUIRED"/> (* com.example.service.*.*(..))"/> ``` 这里,所有的`com.example.service`包下的方法都...
<tx:annotation-driven transaction-manager="transactionManager"/> ``` 5. **拦截器(Interceptor)**: 拦截器用于在方法调用前后执行特定逻辑,如权限检查、日志记录等。在Spring MVC中,我们通常通过`...