欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

简易SSM集成实战教程 - 从小项目起步(上篇)

最编程 2024-07-21 22:54:00
...
<?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 https://www.springframework.org/schema/context/spring-context.xsd"> <!-- spring配置文件:声明service、dao、工具类、事务配置 --> <!-- 加载外部属性配置文件 --> <context:property-placeholder location="classpath:/conf/jdbc.properties" /> <!-- 声明组件扫描器 --> <context:component-scan base-package="com.songzihao.service" /> <!-- 创建数据源 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <!-- 创建SqlSessionFactory对象 --> <bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:/conf/mybatis.xml" /> </bean> <!-- 创建SqlSession对象,通过反射机制加载dao接口对应的mapper文件 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactoryBeanName" value="factory" /> <property name="basePackage" value="com.songzihao.dao" /> </bean> <!-- 事务配置 --> </beans>