Advertisement
ADL_Rodrigo_Silva

Untitled

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