Question

in my applicationContext.xml i have the following

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="formularyDb" />
    <property name="configLocation"  value="file:/web/sites/drugformulary-spring/config/mybatis-config.xml" />
    <property name="mapperLocations" value="file:/web/sites/drugformulary-spring/mappers/*.xml" />
    <!--<property name="mapperLocations" value="classpath*:org/myd/formulary/mappers/*.xml" />-->
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!--<property name="basePackage" value="org.myd.formulary.drugmaster.dao" />-->
    <property name="basePackage" value="org.myd.formulary.drugmaster" />
</bean>

if i have the property name="basePackage" value="org.myd.formulary.drugmaster" , my DAO(DrugMasterDao) in org.myd.formulary.drugmaster.dao is not found I get the *error:

Invalid bound statement (not found):

But if i change it to property name="basePackage" value="org.myd.formulary.drugmaster.dao, DrugMasterDao is found

I would like to have my dao's in the same packages with its controllers and services. So i am wondering how do i do this (use MapperScannerConfigurer) with different dao's in different packages? They will be all under org.myd.formulary

Was it helpful?

Solution 2

This is what finally worked

<bean id="drugmasterScanner"  class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="org.myd.formulary.**.dao"/>
</bean>

OTHER TIPS

You should probably check out how jpetstore code structure looks like. Mapper interface is meant to map sql statements defined in your xml config, then you could simply inject or autowire automagicaly created mapper beans into DAO beans. lets say(assume that mapper interface is MyMapper):

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="org.myd.formulary.drugmaster.persistence" />
</bean>

<bean id="myDAO" class="org.myd.formulary.drugmaster.dao.MyDAO">
    <property name="mapper" ref="myMapper" />
</bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top