Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <pre>
- spring:
- datasource:
- source:
- driver-class-name: org.sqlite.JDBC
- url: jdbc:sqlite::resources/db/StudentCarrer.db3
- destination:
- driver-class-name: com.mysql.jdbc.Driver
- url: jdbc:mysql://nas4:3306/cku
- username: cku
- password: cku
- </pre>
- <pre>
- @Configuration
- public class DBConfig {
- @Bean(name = "srcDataSource")
- @ConfigurationProperties(prefix = "spring.datasource.source")
- public DataSource srcDataSource() {
- return DataSourceBuilder.create().build();
- }
- @Bean(name = "srcJdbcTemplate")
- public JdbcTemplate srcJdbcTemplate(@Qualifier("srcDataSource") DataSource srcDataSource) {
- return new JdbcTemplate(srcDataSource);
- }
- @Bean(name = "dstDataSource")
- @ConfigurationProperties(prefix = "spring.datasource.destination")
- public DataSource dstDataSource() {
- return DataSourceBuilder.create().build();
- }
- @Bean(name = "dstJdbcTemplate")
- public JdbcTemplate dstJdbcTemplate(@Qualifier("dstDataSource") DataSource dstDataSource) {
- return new JdbcTemplate(dstDataSource);
- }
- }
- </pre>
- <pre>
- @Component
- public class DBImporter {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
- @Autowired @Qualifier("srcDataSource")
- public DataSource srcDataSource;
- @Autowired @Qualifier("srcJdbcTemplate")
- public JdbcTemplate srcJdbcTemplate;
- @Autowired @Qualifier("dstDataSource")
- public DataSource dstDataSource;
- @Autowired @Qualifier("dstJdbcTemplate")
- public JdbcTemplate dstJdbcTemplate;
- }
- </pre>
- <pre>
- ***************************
- APPLICATION FAILED TO START
- ***************************
- Description:
- Field srcDataSource in com.cku.assmt.dbimp.DBImporter required a single bean, but 2 were found:
- - srcDataSource: defined by method 'srcDataSource' in class path resource [com/cku/assmt/dbimp/DBConfig.class]
- - dstDataSource: defined by method 'dstDataSource' in class path resource [com/cku/assmt/dbimp/DBConfig.class]
- Action:
- Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
- </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement