1.Haga que el método tenga éxito o falle a través de anotaciones
paquete jar :
transacción: spring-> lib-> spring-tx-4.3.10.RELEASE .jar
base de datos: ojdbc .jar
fuente de datos: commons-dbcp-1.4 .jar
grupo de conexiones: commons-pool.jar
springJDBC: spring-jdbc -4.3.10.RELEASE .jar
AOP: aopalliance-1.0 .jar
Por supuesto, si está usando IDEA, no necesita usar estos, jajajaja
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>