- <?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"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
- <!-- 数据源和mapper -->
- <!-- 配置数据库信息 -->
- <bean
id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property
name="driverClassName"
value="com.mysql.jdbc.Driver"/>
- <property
name="url"
value="jdbc:mysql://localhost:3306/project"/>
- <property
name="username"
value="root"/>
- <property
name="password"
value="admin"/>
- </bean>
-
- <!-- 配置sqlSessionFactory -->
- <bean
id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
- <property
name="dataSource"
ref="dataSource"/>
- <!--加载所有的的mapper映射文件-->
- <property
name="mapperLocations"
value="classpath:cn/tri/mapper/*.xml"></property>
- </bean>
-
- <!-- spring整合mybaties-->
- <!-- 自动扫描包,并且生成mapper的实现类,生成的bean的名称为mapper接口的首字母小写 -->
- <bean
id="mappers"
class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <!-- 配置映射文件 ,该包下的接口统统转化成类,例如 personMapper(首字母小写)-->
- <property
name="basePackage"
value="cn.tri.mapper"></property>
- <!-- 将mybaites的sqlSessionFactory交给spring管理 -->
- <property
name="sqlSessionFactoryBeanName"
value="sqlSessionFactory"></property>
- </bean>
-
- <bean
id="personServiceImp"
class="cn.tri.serviceImp.PersonServiceImp">
- ????????<property
name="personMapper"
ref="personMapper"></property>
- </bean>
- <!-- <bean id="servletPerson" class="cn.tri.servlet.ServletPerson">
????????<property name="personService" ref="personServiceImp"></property>
</bean> -->
- </beans>
|