问题:

无法自动装配 @Autowire 出错,说明没有扫描到此包




解决:

1、未扫描某包的目录,加入如下“扫描”配置属性,具体加入哪个配置文件,数据库相关的放在spring-mabatis联合配置文件或者mybatis配置文件中都行,service等放在springMVC配置文件下即可

<context:component-scan base-package="com.spring.controller"/>

<context:component-scan base-package="com.spring.service"/>
<context:component-scan base-package="com.spring.entity"/>
<context:component-scan base-package="com.spring.dto"/>

2、在mybatis中配置了扫描路径,但未引入到spring配置中

==》在springsqlsessionfactory中配置configlocation,将mabatis的配置文件引入进来

<!-- 4   配置sessionfactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
    <!-- 自动扫描mapping.xml文件 -->
    <property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>