Advertisement
Guest User

Untitled

a guest
Dec 21st, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <pre>
  2. spring:
  3. datasource:
  4. source:
  5. driver-class-name: org.sqlite.JDBC
  6. url: jdbc:sqlite::resources/db/StudentCarrer.db3
  7. destination:
  8. driver-class-name: com.mysql.jdbc.Driver
  9. url: jdbc:mysql://nas4:3306/cku
  10. username: cku
  11. password: cku
  12. </pre>
  13.  
  14. <pre>
  15. @Configuration
  16. public class DBConfig {
  17.  
  18. @Bean(name = "srcDataSource")
  19. @ConfigurationProperties(prefix = "spring.datasource.source")
  20. public DataSource srcDataSource() {
  21. return DataSourceBuilder.create().build();
  22. }
  23.  
  24. @Bean(name = "srcJdbcTemplate")
  25. public JdbcTemplate srcJdbcTemplate(@Qualifier("srcDataSource") DataSource srcDataSource) {
  26. return new JdbcTemplate(srcDataSource);
  27. }
  28.  
  29. @Bean(name = "dstDataSource")
  30. @ConfigurationProperties(prefix = "spring.datasource.destination")
  31. public DataSource dstDataSource() {
  32. return DataSourceBuilder.create().build();
  33. }
  34.  
  35. @Bean(name = "dstJdbcTemplate")
  36. public JdbcTemplate dstJdbcTemplate(@Qualifier("dstDataSource") DataSource dstDataSource) {
  37. return new JdbcTemplate(dstDataSource);
  38. }
  39. }
  40. </pre>
  41.  
  42. <pre>
  43. @Component
  44. public class DBImporter {
  45.  
  46. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  47.  
  48. @Autowired @Qualifier("srcDataSource")
  49. public DataSource srcDataSource;
  50.  
  51. @Autowired @Qualifier("srcJdbcTemplate")
  52. public JdbcTemplate srcJdbcTemplate;
  53.  
  54. @Autowired @Qualifier("dstDataSource")
  55. public DataSource dstDataSource;
  56.  
  57. @Autowired @Qualifier("dstJdbcTemplate")
  58. public JdbcTemplate dstJdbcTemplate;
  59. }
  60. </pre>
  61.  
  62. <pre>
  63. ***************************
  64. APPLICATION FAILED TO START
  65. ***************************
  66.  
  67. Description:
  68.  
  69. Field srcDataSource in com.cku.assmt.dbimp.DBImporter required a single bean, but 2 were found:
  70. - srcDataSource: defined by method 'srcDataSource' in class path resource [com/cku/assmt/dbimp/DBConfig.class]
  71. - dstDataSource: defined by method 'dstDataSource' in class path resource [com/cku/assmt/dbimp/DBConfig.class]
  72.  
  73.  
  74. Action:
  75.  
  76. 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
  77. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement