スマートフォン・ジン | Smartphone-Zine

引っ越し先→ https://smartphone-zine.com/

Spring2.0の設定

Spring2.0の設定ファイルは1.xから結構変わってますね~
定義はこんな感じ
<?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:jee="http://www.springframework.org/schema/jee"
    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/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx ">http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

データソースの設定をJNDIから取得するのもこんなに簡単。
    <!--==== DataSource ==============================================-->
    <jee:jndi-lookup id="dataSource" jndi-name="データソース名" />
トランザクションの管理も楽
    <!--==== DataSource transaction manager ==========================-->
    <bean id="txManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
AOPの設定はこんな感じ。xxxxLogicというクラスにinsertXxxxというメソッドがあったらトランザクションを開始する設定。
    <!--==== aop for transaction =====================================-->
    <aop:config>
        <!-- pointcut the execution of any method defined by the BaseLogic interface -->
        <aop:pointcut id="businessLogic"
            expression="execution( com.andsystem.bl..Logic.(..))" />
        <aop:advisor pointcut-ref="businessLogic" advice-ref="txAdvice" />
    </aop:config>
    <!--==== transactional advice ====================================-->
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="insert" rollback-for="java.lang.Exception"/>
            <tx:method name="find
" read-only="true" />
        </tx:attributes>
    </tx:advice>