标签:conf autowire druid 信息 classpath return 配置 let prope
@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 中配置数据源信息
标签:conf autowire druid 信息 classpath return 配置 let prope
原文地址:https://www.cnblogs.com/jsersudo/p/10114033.html