Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mybatis - multiple base package in mapperscan?

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;
} 
like image 858
Karthikaiselvan Avatar asked Oct 25 '25 15:10

Karthikaiselvan


2 Answers

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

like image 114
Gaurav Goel Avatar answered Oct 27 '25 06:10

Gaurav Goel


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

@Configuration
@MapperScan({"com.transactions.persistence.mapper","com.transactions2.persistence.mapper"})
public class MyBatisConfig {
...
...
}
like image 22
Rakshit Khurana Avatar answered Oct 27 '25 05:10

Rakshit Khurana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!