Spring learning_annotation and transaction

1. Make the method all succeed or fail all through annotations

jar package :
transaction: spring->lib-> spring-tx-4.3.10.RELEASE .jar
database: ojdbc .jar
data source: commons-dbcp-1.4 .jar
connection pool: commons-pool.jar
springJDBC: spring-jdbc -4.3.10.RELEASE .jar
AOP: aopalliance-1.0 .jar
Of course, if you are using IDEA, you don't need to use these, hahahaha
Configure Spring :

    <!--配置数据库相关-->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:xe"/>
        <property name="username" value="hr"/>
        <property name="password" value="hr"/>
    </bean>

    <!--配置事务管理器-->
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource">

        </property>
    </bean>

    <!--增加对事务的支持-->
    <tx:annotation-driven transaction-manager="txManager"/>
     <bean id="personDao" class="com.itheima.dao.PersonDaoImpl">

    </bean>
    <bean id="studentServicesImpl" class="com.itheima.service.PersonServiceImpl">
        <property name="personDao" ref="personDao">

        </property>
    </bean>

Insert picture description here

May your heart be like flowers and trees

Guess you like

Origin blog.csdn.net/nbcsdn/article/details/98983400
Recommended