Hi Rick. I am sorry I have not much time to get deeply into this
issues so sorry if I overlook something important.
The scanner is a bean that runs early during the spring startup
process. It runs before the propertiesplaceholderconfigurer so there
may be a problem with the place holders and you already know. But this
cannot happen with a MapperFactoryBean because it is a normal bean an
will be started once the propertiesplaceholderconfigurer has finished
so the problem must be elsewhere...
This problem/bug seems to be in the class
SqlSessionDaoSupport
It tries to autowire both, a sqlSessionFactory and a sqlSessionTemplate with @Autowired. If the later is found it will be used, regardless whether it belongs itself to the correct SqlSessionFactory. The requested SqlSession points to the wrong database in the end.
This will lead to the effect, that you cannot use SqlSessionTemplate and MapperScanner together if multiple databases/SqlSessionFactories are defined.
In my opinion, SqlSessionDaoSupport should not use @Autowired.
One can overcome this problem by disabling autowireing for the SqlSessionTemplate:
<bean id="batchExecutor" class="org.mybatis.spring.SqlSessionTemplate" autowire-candidate="false">
<constructor-arg index="0" ref="sqlSessionFactoryForDatabase1" />
<constructor-arg index="1" value="BATCH" />
</bean>
In your own service classes, you have to force autowireing with
@Resource(name="batchExecutor")
SqlSessionTemplate batchExecutor;
Felix