<!-- transaction -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- trasaction -->
<beans:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<beans:property name="dataSource" ref="dbcpSource"/>
</beans:bean>
->
->
<!-- trasaction tx -->
<!-- @Transactional 을 사용할 수 있게 함 -->
<tx:annotation-driven/>
<beans:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<beans:property name="dataSource" ref="dbcpSource"/>
</beans:bean>
@Controller
@RequestMapping("my")
public class MyController {
@Autowired
private MyService service;
@GetMapping("test")
@ResponseBody
public String test() {
service.test();
return "test called~!";
}
}
@Service
@Transactional
//@Transactional(isolation = )
//@Transactional(rollbackFor = Exception.class)
//@Transactional(noRollbackFor = NullPointerException.class)
//@Transactional(readOnly=true)
//오직 select쿼리만 날리겠다?
public class MyService {
@Autowired
private MyDao dao;
public void test() {
try {
dao.testA();
dao.testB();
} catch (Exception e) {
throw new RuntimeException("내가 생각못한 checked 예외 발생");
}
}
}
@Repository
public class MyDao {
@Autowired
private SqlSession session;
public void testA() {
session.insert("test.a");
}
public void testB() {
session.insert("test.b");
}
}
<mapper namespace="test">
<insert id="a">
INSERT INTO TEST_TB
VALUES('AAA')
</insert>
<insert id="b">
INSERT INTO TEST_TB
VALUES('BBBbbbbbbbbbbbb')
</insert>
</mapper>
@Transactional(rollbackFor = Exception.class)
@Transactional(noRollbackFor = NullPointerException.class)
@Transactional(readOnly=true)
@Transactional(isolation = )