2

如何为 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;
} 
4

2 回答 2

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));

我想我说的有道理。;-)

于 2015-11-24T06:34:05.627 回答
1

您应该在下面尝试使用注释来配置多个基础包:

@配置
@MapperScan({"com.transactions.persistence.mapper","com.transactions2.persistence.mapper"})
公共类 MyBatisConfig {
...
...
}
于 2017-07-12T11:47:34.483 回答