标签:
1、applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans 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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 配置数据源 --> <bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="url" value="jdbc:oracle:thin:@192.168.66.25:1521:orcl"/> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="username" value="jsd1407"/> <property name="password" value="jsd1407"/> </bean> <!-- 配置SqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 依赖数据源 --> <property name="dataSource" ref="ds" /> <!-- 指定要扫描的所有映射配置文件 --> <property name="mapperLocations" value="classpath:com/tarena/entity/*.xml"/> </bean> <!-- 配置MyBatis注解 --> <!-- Spring会根据这段配置,自动扫描带有指定注解的接口, 然后自动创建这个接口的实现类,并使用对应的xml 中的SQL来实现对应的方法。 即,Spring会自动扫描指定包下,带有注定注解的接口。 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 指定要扫描的包 --> <property name="basePackage" value="com.tarena.dao" /> <!-- 指定要扫描的注解,需要自定义 --> <property name="annotationClass" value="com.tarena.annotation.MybatisDao"/> </bean> <!-- 开启注解扫描,支持IOC --> <context:component-scan base-package="com.tarena" /> <!-- 开启MVC注解,支持Spring MVC --> <mvc:annotation-driven /> <!-- 处理请求转发 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
2.spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?> <beans 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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 配置数据源 --> <bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="url" value="jdbc:oracle:thin:@192.168.66.25:1521:orcl"/> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="username" value="jsd1407"/> <property name="password" value="jsd1407"/> </bean> <!-- 配置SqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 依赖数据源 --> <property name="dataSource" ref="ds" /> <!-- 指定要扫描的所有映射配置文件 --> <property name="mapperLocations" value="classpath:com/tarena/entity/*.xml"/> </bean> <!-- 配置MyBatis注解 --> <!-- Spring会根据这段配置,自动扫描带有指定注解的接口, 然后自动创建这个接口的实现类,并使用对应的xml 中的SQL来实现对应的方法。 即,Spring会自动扫描指定包下,带有注定注解的接口。 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 指定要扫描的包 --> <property name="basePackage" value="com.tarena.dao" /> <!-- 指定要扫描的注解,需要自定义 --> <property name="annotationClass" value="com.tarena.annotation.MybatisDao"/> </bean> <!-- 开启注解扫描,支持IOC --> <context:component-scan base-package="com.tarena" /> <!-- 开启MVC注解,支持Spring MVC --> <mvc:annotation-driven /> <!-- 处理请求转发 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
标签:
原文地址:http://www.cnblogs.com/Crow00/p/4575884.html