Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package com.realdolmen.spring;
  2.  
  3.  
  4. import org.apache.commons.dbcp.BasicDataSource;
  5. import org.springframework.boot.autoconfigure.SpringBootApplication;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.Profile;
  8. import org.springframework.jdbc.core.JdbcTemplate;
  9. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  10. import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
  11. import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
  12.  
  13. import javax.sql.DataSource;
  14.  
  15. @SpringBootApplication
  16. public class ZooConfig {
  17. // TODO: add a datasource for the production profile. We will use BasicDataSource from Apache DBCP. Use connection properties for MySQL (url = "jdbc:mysql://localhost:3306/zoo", user = "root", password = "")
  18. @Profile("production")
  19. @Bean
  20. public DataSource dbSource(){
  21. BasicDataSource ds = new BasicDataSource();
  22. ds.setDriverClassName("");
  23. ds.setUrl("jdbc:mysql://localhost:3306/zoo");
  24. ds.setUsername("root");
  25. ds.setPassword("");
  26. return ds;
  27. }
  28. // TODO: add a JDBC template
  29. @Bean
  30. public JdbcTemplate jdbcTemplate(DataSource dbSource){
  31. return new JdbcTemplate(dbSource);
  32. }
  33.  
  34. @Profile("test")
  35. @Bean
  36. public DataSource dbTestSource() {
  37. return new EmbeddedDatabaseBuilder()
  38. .setType(EmbeddedDatabaseType.H2)
  39. .addScript("classpath:schema.sql")
  40. .build();
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement