3

How to configure multiple base packages for mapperconfigurer.

We tried giving comma separated/ semi colon to put multiple base packages.

@Bean
public MapperScannerConfigurer mapper1(Environment env)
throws Exception
{
  MapperScannerConfigurer mapper = new MapperScannerConfigurer();
  mapper.setBasePackage("co.test1.event.mapper1,co.test2.event.mapper2");
  return mapper;
} 

2 Answers2

2

Please read the following Java doc I found in ConfigurableApplicationContext.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";

The reason I brought this up is, I found the following line in MapperScannerConfigurer#postProcessBeanDefinitionRegistry

scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));

I think I made my point. ;-)

Gaurav Goel
  • 325
  • 2
  • 14
2

You should try below with annotations to configure multiple base packages:

@Configuration
@MapperScan({"com.transactions.persistence.mapper","com.transactions2.persistence.mapper"})
public class MyBatisConfig {
...
...
}
Uwe Allner
  • 3,399
  • 9
  • 35
  • 49