MapperScannerConfigurer

MapperScannerConfigurer

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

最佳答案

请阅读我在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));


我想我说的很对。 ;-)

09-15 16:19