Skip to content
Snippets Groups Projects
Commit 488b687e authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

datasource working (but dirty)

parent 3eab0f7a
No related branches found
No related tags found
No related merge requests found
......@@ -131,6 +131,10 @@
<artifactId>spring-data-jpa</artifactId>
<version>1.10.2.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
</dependencies>
<pluginRepositories>
......
package org.hbp.mip.configuration;
import org.hbp.mip.utils.CSVUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
......@@ -22,8 +24,17 @@ import java.util.Properties;
@EntityScan(basePackages = "org.hbp.mip.model")
public class PersistenceConfiguration {
@Autowired
DataSource dataSource;
@Value("#{'${spring.datasource.username:postgres}'}")
String dbUser;
@Value("#{'${spring.datasource.password:pass}'}")
String dbPass;
@Value("#{'${spring.datasource.url:jdbc:postgresql://db:5432/postgres}'}")
String dbUrl;
@Value("#{'${spring.datasource.driver-class-name:org.postgresql.Driver}'}")
String dbDriver;
@Bean
public CSVUtil csvUtil() {
......@@ -33,7 +44,7 @@ public class PersistenceConfiguration {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setDataSource(dataSource());
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
......@@ -45,4 +56,16 @@ public class PersistenceConfiguration {
properties.setProperty("hibernate.show_sql", "true");
return properties;
}
@Bean
@Primary
public DataSource dataSource() {
return DataSourceBuilder
.create()
.username(dbUser)
.password(dbPass)
.url(dbUrl)
.driverClassName(dbDriver)
.build();
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment