Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.realdolmen.spring;
- import org.apache.commons.dbcp.BasicDataSource;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Profile;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
- import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
- import javax.sql.DataSource;
- @SpringBootApplication
- public class ZooConfig {
- // 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 = "")
- @Profile("production")
- @Bean
- public DataSource dbSource(){
- BasicDataSource ds = new BasicDataSource();
- ds.setDriverClassName("");
- ds.setUrl("jdbc:mysql://localhost:3306/zoo");
- ds.setUsername("root");
- ds.setPassword("");
- return ds;
- }
- // TODO: add a JDBC template
- @Bean
- public JdbcTemplate jdbcTemplate(DataSource dbSource){
- return new JdbcTemplate(dbSource);
- }
- @Profile("test")
- @Bean
- public DataSource dbTestSource() {
- return new EmbeddedDatabaseBuilder()
- .setType(EmbeddedDatabaseType.H2)
- .addScript("classpath:schema.sql")
- .build();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement