@Configuration
    @EnableTransactionManagement
    @PropertySource(value = {"classpath:config/source.properties"})
    public class BeanConfig {
     
        @Autowired
        private Environment env;
     
        @Bean(destroyMethod = "close")
        public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(env.getProperty("source.driverClassName").trim());
        dataSource.setUrl(env.getProperty("source.url").trim());
        dataSource.setUsername(env.getProperty("source.username").trim());
        dataSource.setPassword(env.getProperty("source.password").trim());
        return dataSource;
        }
     
        @Bean
        public JdbcTemplate jdbcTemplate() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(dataSource());
        return jdbcTemplate;
        }
    }

src/main/resources/config/source.properties 中配置数据源信息

相关文章:

  • 2021-11-19
  • 2022-01-05
  • 2021-06-21
  • 2021-07-04
  • 2021-09-07
猜你喜欢
  • 2021-10-31
  • 2021-12-28
  • 2022-02-01
  • 2021-06-11
  • 2021-07-25
  • 2021-11-30
  • 2022-02-08
相关资源
相似解决方案