replaced manual configuration with automatic
This commit is contained in:
parent
788dac69ad
commit
e551a7a783
18
pom.xml
18
pom.xml
|
@ -12,7 +12,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
<artifactId>uoa-repository-manager-service</artifactId>
|
<artifactId>uoa-repository-manager-service</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -54,6 +54,15 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -275,13 +284,6 @@
|
||||||
<!-- </exclusions>-->
|
<!-- </exclusions>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>2.26.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
package eu.dnetlib.repo.manager.config;
|
|
||||||
|
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableTransactionManagement
|
|
||||||
public class DatasourceConfiguration {
|
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(DatasourceConfiguration.class);
|
|
||||||
|
|
||||||
@Value("${services.provide.db.driverClassName}")
|
|
||||||
private String driverClassname;
|
|
||||||
|
|
||||||
@Value("${services.provide.db.url}")
|
|
||||||
private String URL;
|
|
||||||
|
|
||||||
@Value("${services.provide.db.username}")
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@Value("${services.provide.db.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public BasicDataSource dataSource(){
|
|
||||||
BasicDataSource basicDataSource = new BasicDataSource();
|
|
||||||
basicDataSource.setDriverClassName(driverClassname);
|
|
||||||
basicDataSource.setUrl(URL);
|
|
||||||
basicDataSource.setUsername(username);
|
|
||||||
basicDataSource.setPassword(password);
|
|
||||||
basicDataSource.setMaxIdle(10);
|
|
||||||
basicDataSource.setMaxActive(100);
|
|
||||||
basicDataSource.setMaxWait(1000);
|
|
||||||
basicDataSource.setValidationQuery("SELECT 1;");
|
|
||||||
basicDataSource.setTestOnBorrow(true);
|
|
||||||
basicDataSource.setTestOnReturn(true);
|
|
||||||
basicDataSource.setTestWhileIdle(true);
|
|
||||||
basicDataSource.setTimeBetweenEvictionRunsMillis(1200000);
|
|
||||||
basicDataSource.setMinEvictableIdleTimeMillis(1800000);
|
|
||||||
basicDataSource.setMinEvictableIdleTimeMillis(5);
|
|
||||||
basicDataSource.setPoolPreparedStatements(true);
|
|
||||||
basicDataSource.setDefaultAutoCommit(true);
|
|
||||||
|
|
||||||
return basicDataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public DataSourceTransactionManager txManager(){
|
|
||||||
DataSourceTransactionManager txManager = new DataSourceTransactionManager();
|
|
||||||
txManager.setDataSource(dataSource());
|
|
||||||
return txManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package eu.dnetlib.repo.manager.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
|
||||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
||||||
import org.springframework.orm.jpa.JpaVendorAdapter;
|
|
||||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
||||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableTransactionManagement
|
|
||||||
public class JpaConfig {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
DataSource dataSource;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
EntityManagerFactory entityManagerFactory;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public PlatformTransactionManager transactionManager() {
|
|
||||||
JpaTransactionManager transactionManager = new JpaTransactionManager();
|
|
||||||
transactionManager.setEntityManagerFactory(entityManagerFactory);
|
|
||||||
|
|
||||||
return transactionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
|
|
||||||
return new PersistenceExceptionTranslationPostProcessor();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +1,18 @@
|
||||||
server:
|
springdoc.swagger-ui:
|
||||||
port: 8480
|
disable-swagger-default-url: true
|
||||||
servlet:
|
version: 3
|
||||||
context-path: /uoa-repository-manager-service
|
|
||||||
|
spring:
|
||||||
|
jpa:
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: update
|
||||||
|
|
||||||
|
datasource:
|
||||||
|
url: ${services.provide.db.url}
|
||||||
|
username: ${services.provide.db.username}
|
||||||
|
password: ${services.provide.db.password}
|
||||||
|
driverClassName: ${services.provide.db.driverClassName}
|
||||||
|
|
||||||
services:
|
services:
|
||||||
provide:
|
provide:
|
||||||
dev-machine: 88.197.53.71
|
dev-machine: 88.197.53.71
|
||||||
|
|
Loading…
Reference in New Issue