Multi MapperScannerConfigurer spring placeHolder problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Multi MapperScannerConfigurer spring placeHolder problem

WalterInSH
Hi

I'm using mybatis-spring. My project has 2 datasource so I wrote 2 sqlSessionFactory.
I found the spring placeHolder's not working even though I use sqlSessionFactoryBeanName and value(not ref) when I config MapperScannerConfigurer.
Everything worked fine if I use single MapperScannerConfigurer.

So does that mean I cannot use multi MapperScannerConfigurer?

Mybatis version 3.1.1
Mybatis-Spring version 1.1.0

<bean id="FactoryA" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property
name="dataSource" ref="DSA" />
        <property
name="configLocation"
                value="sqlMapConfig.xml" />
        <property
name="mapperLocations"
                value="classpath:/mapper/sql/*.xml" />
</bean>


<bean id="ScannerA" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property
name="basePackage" value="dao.mapper" />
        <property
name="sqlSessionFactoryBeanName" value="FactoryA" />
</bean>


   
<!--second data-->
   
<bean id="FactoryB" class="org.mybatis.spring.SqlSessionFactoryBean">
       
<property
name="dataSource" ref="DSB" />
       
<property
name="configLocation"
                 
value="sqlMapConfig.xml" />

      <property name="mapperLocations"
                 
value="classpath:metasql/*.xml" />
   
</bean>

   
<bean
id="ScannerB" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       
<property
name="basePackage" value="dao.metamapper" />
       
<property
name="sqlSessionFactoryBeanName" value="FactoryB" />
   
</bean>



--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multi MapperScannerConfigurer spring placeHolder problem

Iwao AVE!
Hi,

There seems to be some people who are using similar setup.

The versions of mybatis and mybatis-spring are very old.
You should try with the latest version unless there is a very good reason.

If you provide a demo app to reproduce the error, you might get more useful answers.
There is a skeleton project for mybatis-spring.

Regards,
Iwao

2016-09-08 15:35 GMT+09:00 WalterInSH <[hidden email]>:
Hi

I'm using mybatis-spring. My project has 2 datasource so I wrote 2 sqlSessionFactory.
I found the spring placeHolder's not working even though I use sqlSessionFactoryBeanName and value(not ref) when I config MapperScannerConfigurer.
Everything worked fine if I use single MapperScannerConfigurer.

So does that mean I cannot use multi MapperScannerConfigurer?

Mybatis version 3.1.1
Mybatis-Spring version 1.1.0

<bean id="FactoryA" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property
name="dataSource" ref="DSA" />
        <property
name="configLocation"
                value="sqlMapConfig.xml" />
        <property
name="mapperLocations"
                value="classpath:/mapper/sql/*.xml" />
</bean>


<bean id="ScannerA" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property
name="basePackage" value="dao.mapper" />
        <property
name="sqlSessionFactoryBeanName" value="FactoryA" />
</bean>


   
<!--second data-->
   
<bean id="FactoryB" class="org.mybatis.spring.SqlSessionFactoryBean">
       
<property
name="dataSource" ref="DSB" />
       
<property
name="configLocation"
                 
value="sqlMapConfig.xml" />

      <property name="mapperLocations"
                 
value="classpath:metasql/*.xml" />
   
</bean>

   
<bean
id="ScannerB" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       
<property
name="basePackage" value="dao.metamapper" />
       
<property
name="sqlSessionFactoryBeanName" value="FactoryB" />
   
</bean>



--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multi MapperScannerConfigurer spring placeHolder problem

Rick R
Also, how are you 100% sure it's the second data source config as the issue?  If you remove the FactoryA config does a test work for FactoryB? if you then put back FactoryA and remove FactoryB's how does it work (testing just FactoryA)
Sometimes you think it's your extra config when it's something unrelated causing the issue, so be sure you test each stand alone within the app.

Note, I notice for your scanners you have it set up with a different path in the mapperLocations...one has the leading '/' the other doesn't.   I never set up the mapperLocations like you have so not sure if that's an issue or not. (never had a need to since I think the basePackage is enough.)
I also don't set up a configLocation either.


lasty try these later versions as Iwao points out

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>


On Wed, Sep 21, 2016 at 10:10 AM, Iwao AVE! <[hidden email]> wrote:
Hi,

There seems to be some people who are using similar setup.

The versions of mybatis and mybatis-spring are very old.
You should try with the latest version unless there is a very good reason.

If you provide a demo app to reproduce the error, you might get more useful answers.
There is a skeleton project for mybatis-spring.

Regards,
Iwao

2016-09-08 15:35 GMT+09:00 WalterInSH <[hidden email]>:
Hi

I'm using mybatis-spring. My project has 2 datasource so I wrote 2 sqlSessionFactory.
I found the spring placeHolder's not working even though I use sqlSessionFactoryBeanName and value(not ref) when I config MapperScannerConfigurer.
Everything worked fine if I use single MapperScannerConfigurer.

So does that mean I cannot use multi MapperScannerConfigurer?

Mybatis version 3.1.1
Mybatis-Spring version 1.1.0

<bean id="FactoryA" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property
name="dataSource" ref="DSA" />
        <property
name="configLocation"
                value="sqlMapConfig.xml" />
        <property
name="mapperLocations"
                value="classpath:/mapper/sql/*.xml" />
</bean>


<bean id="ScannerA" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property
name="basePackage" value="dao.mapper" />
        <property
name="sqlSessionFactoryBeanName" value="FactoryA" />
</bean>


   
<!--second data-->
   
<bean id="FactoryB" class="org.mybatis.spring.SqlSessionFactoryBean">
       
<property
name="dataSource" ref="DSB" />
       
<property
name="configLocation"
                 
value="sqlMapConfig.xml" />

      <property name="mapperLocations"
                 
value="classpath:metasql/*.xml" />
   
</bean>

   
<bean
id="ScannerB" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       
<property
name="basePackage" value="dao.metamapper" />
       
<property
name="sqlSessionFactoryBeanName" value="FactoryB" />
   
</bean>



--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Rick R

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.