Spring Refrence에 있는 설정 파일을 보도록 하겠습니다.

<?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">

//bean 설정이 들어갈 곳

</beans>

XML에서 사용 할 트랜잭션 관련 XML스키마를 추가 합니다. 그리고 bean 설정이 들어갈 곳에 트랜잭션 어드바이스를 추가합니다.

<tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="get*" read-only="true" />
            <tx:method name="*" />
        </tx:attributes>
</tx:advice>

get으로 시작하는 메소드는 read-only 상태로 읽고 나머지 메소드는 기본 설정 대로 트랜잭션 속성을 지정한 트랜잭션 어드바이스를 만듭니다.

transaction-manager 속성에 넣어준 bean은 다음과 같습니다.

<bean id="txManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
</bean>

실제 트랜잭션을 관리할 bean으로 만약 이 bean의 이름을 transactionManager 라고 설정했다면 트랙잰션 어드바이스에서 굳이 transaction-manager 속성을 사용하여 명시하지 않더라도 알아서 찾을 수 있습니다.[footnote]이것도 일종의 CoC라고 할 수 있겠습니다.[/footnote] 트랜잭션 관리 대상이 될 dataSource를 주입해줘야 하는 군요. 그건 그냥 하면 되겠죠.

다시 돌아가서 트랜잭션 어드바이스를 주입할 포인트 컷과 묶어서 어드바이저를 만들어 줍니다.

<aop:config>
        <aop:pointcut id="fooServiceOperation"
            expression="execution(* x.y.service.FooService.*(..))" />
        <aop:advisor advice-ref="txAdvice"
            pointcut-ref="fooServiceOperation" />
</aop:config>

이렇게 설정 해 두면 FooService에 있는 모든 메소드에 트랜잭션 어드바이스가 적용될 것입니다. 모든 service 패키지에 있는 모든 클래스의 모든 메소드에 적용하고 싶다면 위의 빨간글씨 부분을 다음과 같이 수정하면 됩니다. x.y.service.*.*(..))