LoginSignup
0
1

More than 5 years have passed since last update.

spring boot 複数DBに接続時interceptor無効になるについて

Posted at

step1

@Import({DataSourceConfiguration.class,PageInterceptor.class})

step2

@Autowired
    private PageInterceptor pageInterceptor;

step3

sqlSessionFactoryBean.setPlugins(newInterceptor[]{pageInterceptor});

step3は「sqlSessionFactoryBean.getObject()」前に書く

原因

sqlSessionFactoryBean.getObject()
public SqlSessionFactory getObject() throws Exception {
    if (this.sqlSessionFactory == null) {
      afterPropertiesSet();
    }

    return this.sqlSessionFactory;
}
public void afterPropertiesSet() throws Exception {
    notNull(dataSource, "Property 'dataSource' is required");
    notNull(sqlSessionFactoryBuilder, "Property 'sqlSessionFactoryBuilder' is required");
    state((configuration == null && configLocation == null) || !(configuration != null && configLocation != null),
              "Property 'configuration' and 'configLocation' can not specified with together");

    this.sqlSessionFactory = buildSqlSessionFactory();
  }
if (!isEmpty(this.plugins)) {
      for (Interceptor plugin : this.plugins) {
        configuration.addInterceptor(plugin);
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Registered plugin: '" + plugin + "'");
        }
      }
    }
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1