首页 > 编程语言 > 详细

springboot手动配置数据源:

时间:2018-12-13 15:22:31      阅读:522      评论:0      收藏:0      [点我收藏+]
@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 中配置数据源信息

springboot手动配置数据源:

原文:https://www.cnblogs.com/jsersudo/p/10114033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!