applicationContext
命名空间:
引入命名空间,这样可以在代码中使用annotation
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
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.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:annotation-config/>
<!-- 注册并将bean交给IOC容器控制,但是不注册controller类-->
<context:component-scan base-package:"com.wtw.*">
<context:exclude-filter: type:"annotation" expression="org.springframework.stereotype.Controller"
</context:compnent-scan>
<!-- 导入数据库连接配置文件-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 数据库连接池-->
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destory-method="close">
<property name="driverClassName" value="${driverClass}"/>
<property name="url" value="${jdbcurl}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
<!-- 配置jdbcTemplate -->
<bean name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 采用注解的方式配置事务-->
<bean name="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>