Advertisement
ADL_Rodrigo_Silva

Untitled

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