spring整合mybatis相关问题

        最近开发一个会员接口,由于公司想要把这个接口独立,因此我在项目里重新建了一个包,把跟这个接口相关的Controller、Service、Dao、mapper文件都单独写出来,如项目原来的结构是com.aa.www,我新加的目录是com.bb.www,我把在这个过程中遇到的一些跟spring和mybatis整合相关的问题,记录下来。

 1   把Contrllor加入Spring mvc管理

         需要在spring-servlet.xml文件中加入这个包的路径:如下面,原来我的base-package为com.aa.www,现在为了把我的com.bb.www也加入管理,我把base-package改成com.*.www,这样就好了。  

<context:component-scan base-package="com.*.www" use-default-filters="false">
	<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>

2   把Service加入applicationContext.xml管理

     Service也要加入spring管理,需要在applicationContext.xml文件中把com.bb.www加上

<context:component-scan base-package="com.aa.www"/>
<context:component-scan base-package="com.bb.www"/>

3  把Mapper文件也加入applicationContext.xml管理

    把mapper文件的calsspath*:com/aa/**/mapper/*.xml改成classpath*:com/*/**/mapper/*.xml

<property name="mapperLocations" value="classpath*:com/*/**/mapper/*.xml" />

猜你喜欢

转载自wzf7065.iteye.com/blog/2376526