applicationContext.xml



例:连接JDBC和管理事务

1,beans的声明处添加相应的命名空间的schema定义文件的说明,这样在配置文件中就可以使用对应空间下的配置标签了。
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:p=" http://www.springframework.org/schema/p" 
xmlns:context=" http://www.springframework.org/schema/context" 
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

2,将 注解的类自动转化Bean,同时完成Bean的注入 -->
 项目包名添加到上下文扫描路径,以便包中类里的Spring注解生效。
 
 
  destroy-method="close" 
  p:driverClassName="com.mysql.jdbc.Driver"
  p:url="jdbc:mysql://localhost:3306/sampledb" 
  p:username="root"
  p:password="root" />

3-2,定义JDBC模版bean
 
 
  p:dataSource-ref="dataSource" />

3-3,配置事务管理器,负责声明式事务的管理,需引用dataSource Bean
 
 
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
  p:dataSource-ref="dataSource" />

4,通过aop和tx命名空间的语法,以AOP的方式为项目包下所有类的所有方法都添加事务增强,即它们都将工作在事务环境中。
 
 
 
   expression="execution(*com.baobaotao.service..*(..))" />
 
 

例:连接JDBC和管理事务

1,beans的声明处添加相应的命名空间的schema定义文件的说明,这样在配置文件中就可以使用对应空间下的配置标签了。
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:p=" http://www.springframework.org/schema/p" 
xmlns:context=" http://www.springframework.org/schema/context" 
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

2,将 注解的类自动转化Bean,同时完成Bean的注入 -->
 项目包名添加到上下文扫描路径,以便包中类里的Spring注解生效。
 
 
  destroy-method="close" 
  p:driverClassName="com.mysql.jdbc.Driver"
  p:url="jdbc:mysql://localhost:3306/sampledb" 
  p:username="root"
  p:password="root" />

3-2,定义JDBC模版bean
 
 
  p:dataSource-ref="dataSource" />

3-3,配置事务管理器,负责声明式事务的管理,需引用dataSource Bean
 
 
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
  p:dataSource-ref="dataSource" />

4,通过aop和tx命名空间的语法,以AOP的方式为项目包下所有类的所有方法都添加事务增强,即它们都将工作在事务环境中。
 
 
 
   expression="execution(*com.baobaotao.service..*(..))" />
 
 

你可能感兴趣的:(Spring)