Problem with MapperScannerConfigurer and multiple data sources

986 views
Skip to first unread message

icfantv

unread,
Jan 4, 2012, 11:35:06 AM1/4/12
to mybati...@googlegroups.com
With one data source defined, I can get by with this:

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.foo.persistence"/>
</bean>

and everything works fine. It's scanning my mappers and everything is
happy. Tests pass and little birds sing.

When trying to configure and use multiple data sources, per the
documentation here: http://www.mybatis.org/spring/mappers.html, I tried
setting

<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />

but it fails because there is no setter method on MapperScannerConfigurer by
that name. Indeed, there's no setter in the entire mybatis-spring API with
that name.

I tried setting the SQL session factory directly like so:

<property name="sqlSessionFactory" ref="bmsSqlSessionFactory"/>

But this breaks Spring's parsing of my application-config.xml file and my
${property_name} properties for my data source are not replaced with the
correct values and are interpreted literally as "${property_name}".

I was using the annotationClass property to filter the scanning and based on
the debug logging I could see that this was working as designed, filtering
my mappers accordingly, but because the properties were not de-referenced as
above, the construction of my data source was failing.

Anyone have any clue as to what's going on here and how I can configure
multiple mapper scanners? Thanks,

--adam

--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Problem-with-MapperScannerConfigurer-and-multiple-data-sources-tp3632339p3632339.html
Sent from the mybatis-user mailing list archive at Nabble.com.

Eduardo

unread,
Jan 4, 2012, 1:45:54 PM1/4/12
to mybatis-user
Hi adam,

That is a know problem of mybatis-spring 1.0.2. It is not compatible
with the PropertyPlaceholderConfigurer because it run earlier during
the startup process.

That is why on 1.1.0 those properties are going to be replaced by
sqlSessionFactoryBeanName and sqlSessionTemplateBeanName.

You have two options:
- Go 1.1.0-SNAPSHOT (and MyBatis 3.1.0-SNAPSHOT) that are very close
to the final releases.
- Use SPEL instead of the PropertyPlaceholderConfigurer. Have a look
at this [1]

[1] http://code.google.com/p/mybatis/issues/detail?id=414

icfantv

unread,
Jan 4, 2012, 3:15:26 PM1/4/12
to mybati...@googlegroups.com
Oh awesome! Thanks!

I was worried we were going to have to create synonyms in one database that
point to another. Very stinky, indeed.

--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Problem-with-MapperScannerConfigurer-and-multiple-data-sources-tp3632339p3632931.html

Reply all
Reply to author
Forward
0 new messages