DataSourceConfig.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.yihu.ehr.oauth2.config;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
  4. import org.springframework.boot.context.properties.ConfigurationProperties;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.context.annotation.Primary;
  8. import org.springframework.data.redis.connection.RedisConnectionFactory;
  9. import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
  10. import org.springframework.jdbc.core.JdbcTemplate;
  11. import javax.sql.DataSource;
  12. /**
  13. * Created by Administrator on 2017/2/21.
  14. */
  15. @Configuration
  16. public class DataSourceConfig {
  17. /**
  18. * 主数据源
  19. *
  20. * @return
  21. */
  22. @Bean
  23. @Primary//主库 默认不写名字用这个
  24. @ConfigurationProperties(prefix = "spring.datasource")
  25. public DataSource primaryReadWriteDataSource() {
  26. return DataSourceBuilder.create().build();
  27. }
  28. @Bean
  29. public JdbcTemplate jdbcTemplate(DataSource dataSource) {
  30. JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  31. return jdbcTemplate;
  32. }
  33. }