Advertisement
ImHungryHi

dbconfig

Sep 17th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. package cc.serviceops.config;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.context.annotation.PropertySource;
  6. import org.springframework.core.env.Environment;
  7. import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  8. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  9. import org.springframework.transaction.annotation.EnableTransactionManagement;
  10. import javax.sql.DataSource;
  11.  
  12. @Configuration
  13. @PropertySource("classpath:application.properties")
  14. @EnableTransactionManagement
  15. @EnableJpaRepositories("cc.serviceops")
  16. public class DatabaseConfig {
  17. private Environment environment;
  18.  
  19. @Autowired
  20. public void setEnvironment(Environment environment) {
  21. this.environment = environment;
  22. }
  23.  
  24. @Bean
  25. public DataSource getDataSource() {
  26. DriverManagerDataSource dataSource = new DriverManagerDataSource();
  27. dataSource.setDriverClassName(environment.getProperty("spring.datasource.driver-class-name"));
  28. dataSource.setUrl(environment.getProperty("spring.datasource.url"));
  29. dataSource.setUsername(environment.getProperty("spring.datasource.username"));
  30. dataSource.setPassword(environment.getProperty("spring.datasource.password"));
  31. return dataSource;
  32. }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement