Spring-jdbc-注解
来源:互联网 发布:荒蛮故事 知乎 编辑:程序博客网 时间:2024/06/15 03:01
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><context:component-scan base-package="cn.itcast.spring0909.jdbc.transaction.annotation"></context:component-scan><!-- dataSource --> <beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><value>classpath:jdbc.properties</value></property></bean><bean id="dataSource" destroy-method="close"class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName" value="${jdbc.driverClassName}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><!-- <property name="password" value="${jdbc.password}" /> --></bean><!-- jdbcTemplate --><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource"><ref bean="dataSource"/></property></bean><!-- 事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean><!-- 启动事务的注解解析器 --><tx:annotation-driven transaction-manager="transactionManager"/></beans>
public interface PersonDao {public void savePerson();}
@Repository("personDao")public class PersonDaoImpl implements PersonDao{@Resource(name="jdbcTemplate")//这里这能保存jdbcTemplate变量的方式不能继承jdbcSupportprivate JdbcTemplate jdbcTemplate;@Overridepublic void savePerson() {// TODO Auto-generated method stubthis.jdbcTemplate.execute("insert into person(pname) values('aa')");int a = 1/0;this.jdbcTemplate.execute("insert into person(pname) values('aa')");}}
public interface PersonService {public void savePerson();}
@Service("personService")public class PersonServiceImpl implements PersonService{@Resource(name="personDao")private PersonDao personDao;/** * 注解的粒度比xml要细 */@Transactional(readOnly=false)//这才是重点public void savePerson() {// TODO Auto-generated method stubthis.personDao.savePerson();}}
////上面的代码才是重点
public class PersonTest extends SpringHelper{static{path = "cn/itcast/spring0909/jdbc/transaction/annotation/applicationContext.xml";}@Testpublic void test(){PersonService personService = (PersonService)context.getBean("personService");personService.savePerson();}}
0 0
- Spring-jdbc-注解
- 8.Spring + JDBC + 事务(注解)
- Spring-Jdbc的配置和注解
- AOP注解配置+Spring整合JDBC+Spring整合ibatis
- 【Spring】在Spring框架下使用注解配置JDBC事务
- 使用注解方式配置spring中的jdbc事务
- 基于注解的SpringMVC+Spring JDBC template+JSTL-demo练习
- Spring+SpringMVC+Mybatis+jdbc基础框架搭建(注解版)
- Spring JDBC-使用注解配置声明式事务
- Spring整合JDBC、Spring的AOP事务开发、Spring注解整理
- spring学习笔记10--Spring+jdbc组合开发(注解方式配置事务)
- Spring学习5-Spring整合JDBC及其事务处理(注解方式)
- spring注解--组合注解
- Spring JDBC
- spring+JDBC
- Spring JDBC
- spring + jdbc
- Spring JDBC
- sql笔试题(2)
- Monkey命令格式
- iOS7.1企业应用"无法安装应用程序 因为证书无效"的完美解决方案
- properties文件jar 路径
- Asterisk - dual servers Connecting two Asterisk servers
- Spring-jdbc-注解
- asp.net mvc3标识和事物
- DAO层实现代码封装模板
- 设计模式 关注点分离
- Tomcat 生产服务器性能优化
- subilme 打开文件异常
- UVa 348 Optimal Array Multiplication Sequence(dp)
- asp.net mvc remote提交
- 使用CSS完美实现垂直居中的方法