整合ssm的问题(1)
(1)测试spring-mybatis整合时无论怎么都扫描不到dao接口的映射文件
出现异常:
前提在applicationContext配置好:
<?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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 配置spring扫描包 -->
<context:component-scan base-package="com.ccl">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 引入jdbc.properties -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置c3p0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- 当连接池中连接耗尽c3p0一次同时获取的连接数 -->
<property name="acquireIncrement" value="5"/>
<!-- 初始连接池大小 -->
<property name="initialPoolSize" value="10"/>
<!-- 连接池中连接最小个数-->
<property name="minPoolSize" value="5"/>
<!-- 连接池中最大连接个数-->
<property name="maxPoolSize" value="20"/>
</bean>
<!-- 创建会话工厂-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据源-->
<property name="dataSource" ref="dataSource"/>
<!-- 配置别名-->
<property name="typeAliasesPackage" value="com.ccl.domain"/>
<!-- 配置MySQL映射文件的路径-->
<property name="mapperLocations" value="classpath*:com/ccl/dao/I*Dao.xml"/>
</bean>
<!-- 自动扫描dao接口的映射文件 -->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<property name="basePackage" value="com.ccl.dao"/>
</bean>
</beans>
问题所在:spring配置不会读取除了resources资源文件下的.xml文件,修改maven配置即可。
解决方法:
在pom.xml中添加如下配置:(< build > < / build >标签中)
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>