ssm整合的spring.xml文件配置(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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="com.aaa.ssm.service"></context:component-scan>
<!--創建dbcp數據源連接池對象-->
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<!--創建mybatis的SqlSessionFactory工廠類對象-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--指定mapper文件的地址 此處可以使用*號同配置,表示加載包下所有的xml結尾的mapper文件-->
<property name="mapperLocations" value="classpath:com/aaa/ssm/dao/*.xml"></property>
</bean>
<!--配置掃描mybatis的dao接口 ,會為dao接口創建myabtis的dao接口實現類對象,放置到session工廠中-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--指定dao接口在哪個包中-->
<property name="basePackage" value="com.aaa.ssm.dao"></property>
</bean>

<!--聲明spring 的事物管理器對象-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--聲明以注解的方式配置spring 的事物-->
<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
</beans>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM