如何为mapperconfigurer配置多个基本包。
我们尝试使用逗号分隔/半冒号来放置多个基础包。
@Bean
public MapperScannerConfigurer mapper1(Environment env)
throws Exception
{
MapperScannerConfigurer mapper = new MapperScannerConfigurer();
mapper.setBasePackage("co.test1.event.mapper1,co.test2.event.mapper2");
return mapper;
}
答案 0 :(得分:2)
请阅读我在ConfigurableApplicationContext.java
中找到的以下Java文档/**
* Any number of these characters are considered delimiters between
* multiple context config paths in a single String value.
* @see org.springframework.context.support.AbstractXmlApplicationContext#setConfigLocation
* @see org.springframework.web.context.ContextLoader#CONFIG_LOCATION_PARAM
* @see org.springframework.web.servlet.FrameworkServlet#setContextConfigLocation
*/
String CONFIG_LOCATION_DELIMITERS = ",; \t\n";
我提出这个问题的原因是,我在MapperScannerConfigurer#postProcessBeanDefinitionRegistry
中找到以下行scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
我想我明白了。 ; - )
答案 1 :(得分:1)
您应该在下面尝试使用注释来配置多个基础包:
@Configuration @MapperScan({"com.transactions.persistence.mapper","com.transactions2.persistence.mapper"}) public class MyBatisConfig { ... ... }