Advertisement
ADL_Rodrigo_Silva

Untitled

Mar 8th, 2022
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package com.latam.jpacrud;
  2.  
  3. import javax.sql.DataSource;
  4.  
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.ComponentScan;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.context.annotation.PropertySource;
  10. import org.springframework.core.env.Environment;
  11. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  12.  
  13. @Configuration
  14. @ComponentScan("com.latam.jpacrud")
  15. @PropertySource("classpath:database.properties")
  16. public class AppConfig {
  17.    
  18.     @Autowired
  19.     Environment environment;
  20.    
  21.     @Bean
  22.     DataSource dataSource() {
  23.        
  24.         DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
  25.         driverManagerDataSource.setUrl(environment.getProperty("url"));
  26.         driverManagerDataSource.setUsername(environment.getProperty("dbuser"));
  27.         driverManagerDataSource.setPassword(environment.getProperty("dbpassword"));
  28.         driverManagerDataSource.setDriverClassName(environment.getProperty("driver"));
  29.        
  30.         return driverManagerDataSource;
  31.        
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement