Spring+Mybatis下applicationContext.xml和mybatis-config.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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"
     >
     
    <bean id="config" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
        <property name="locations">
        <list>
                <value>classpath:database.propertiesvalue>
        list>
        property>
    bean>
    
    
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName">
            <value>${driver}value>
        property>
        <property name="url">
            <value>${url}value>
        property>
        <property name="username">
            <value>${user}value>
        property>
        <property name="password">
            <value>${password}value>
        property>
    bean>
    
    
    
    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis-config.xml" />
    bean>
    
    
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.dao" />
    bean>
    
    
    <context:annotation-config />
    <context:component-scan base-package="com.service" />
    
    
    
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    bean>
    <tx:annotation-driven transaction-manager="txManager"/>

beans>







以下是整合后的mybatis-config.xml文件(可以不需要)
xml version="1.0" encoding="UTF-8" ?>
DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">


<configuration>


<settings>


<setting name="autoMappingBehavior" value="FULL"/>
settings>


<typeAliases>
<package name="com.pojo"/>
typeAliases>

configuration>

 

 

 

转载于:https://www.cnblogs.com/EzioSyh/p/6916369.html

你可能感兴趣的:(Spring+Mybatis下applicationContext.xml和mybatis-config.xml配置文件)