How to java-configure separate datasources for spring batch data and business data? Should I even do it?

后端 未结 7 1560
感情败类
感情败类 2020-11-29 22:33

My main job does only read operations and the other one does some writing but on MyISAM engine which ignores transactions, so I wouldn\'t require necessarily tr

7条回答
  •  执笔经年
    2020-11-29 22:50

    Have you tried something like this already?

    @Bean(name="batchDataSource")
    public DataSource batchDataSource(){          
           return DataSourceBuilder.create()
                    .url(env.getProperty("batchdb.url"))
                    .driverClassName(env.getProperty("batchdb.driver"))
                    .username(env.getProperty("batchdb.username"))
                    .password(env.getProperty("batchdb.password"))
                    .build();          
    } 
    

    and then mark the other datasource with a @Primary, and use an @Qualifier in your batch config to specify that you want to auotwire the batchDataSource bean.

提交回复
热议问题