2.配置applicationContext.xml
阿新 • • 發佈:2020-08-24
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.xsd"> <context:property-placeholder location="classpath:db.properties"/> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- 事務處理:略--> <!-- aop切面:略--> <!-- 配置mybatis工廠--> <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory"> <property name="configLocation" value="classpath:mybatis-config.xml"/> <!-- 配置MyBatis的核心配置檔案所在位置--> <property name="dataSource" ref="dataSource"/> </bean> <!-- 介面開發,掃描com.bm.dao包,寫在此包下的介面即可被掃描--> <!--mybatis-config.xml配置的mapper就不用寫了--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.bm.dao"/> </bean> <!-- 配置掃描@Service註解--> <context:component-scan base-package="com.bm.service"/> </beans>