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

clean more again datasource configuration import

parent ad12037c
No related branches found
No related tags found
No related merge requests found
package org.hbp.mip.configuration; package org.hbp.mip.configuration;
import org.hbp.mip.utils.CSVUtil; import org.hbp.mip.utils.CSVUtil;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityScan; import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
...@@ -24,6 +22,9 @@ import java.util.Properties; ...@@ -24,6 +22,9 @@ import java.util.Properties;
@EntityScan(basePackages = "org.hbp.mip.model") @EntityScan(basePackages = "org.hbp.mip.model")
public class PersistenceConfiguration { public class PersistenceConfiguration {
@Autowired
DataSource dataSource;
@Bean @Bean
public CSVUtil csvUtil() { public CSVUtil csvUtil() {
return new CSVUtil(); return new CSVUtil();
...@@ -32,7 +33,7 @@ public class PersistenceConfiguration { ...@@ -32,7 +33,7 @@ public class PersistenceConfiguration {
@Bean @Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource()); em.setDataSource(dataSource);
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter); em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties()); em.setJpaProperties(additionalProperties());
...@@ -44,13 +45,4 @@ public class PersistenceConfiguration { ...@@ -44,13 +45,4 @@ public class PersistenceConfiguration {
properties.setProperty("hibernate.show_sql", "true"); properties.setProperty("hibernate.show_sql", "true");
return properties; return properties;
} }
@ConfigurationProperties("spring.datasource")
@Bean
@Primary
public DataSource dataSource() {
return DataSourceBuilder
.create()
.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