SUPPORT-9212: рефактор
This commit is contained in:
parent
498eb5bf36
commit
8f9d392374
1 changed files with 21 additions and 27 deletions
|
|
@ -6,12 +6,8 @@ import java.time.Duration;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import ervu_business_metrics.deserializer.ReferenceEntityDeserializer;
|
import ervu_business_metrics.deserializer.ReferenceEntityDeserializer;
|
||||||
import ervu_business_metrics.model.ReferenceEntity;
|
import ervu_business_metrics.model.ReferenceEntity;
|
||||||
import exception.AppInitializeException;
|
import exception.AppInitializeException;
|
||||||
|
|
@ -20,26 +16,21 @@ import net.javacrumbs.shedlock.core.LockProvider;
|
||||||
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
|
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
|
||||||
import net.javacrumbs.shedlock.spring.ScheduledLockConfiguration;
|
import net.javacrumbs.shedlock.spring.ScheduledLockConfiguration;
|
||||||
import net.javacrumbs.shedlock.spring.ScheduledLockConfigurationBuilder;
|
import net.javacrumbs.shedlock.spring.ScheduledLockConfigurationBuilder;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.*;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
|
||||||
import org.springframework.context.annotation.FilterType;
|
|
||||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Root application context
|
* Root application context This context imports XML configs from all the other jars, and is created
|
||||||
* This context imports XML configs from all the other jars, and is created by {@link WebAppInitializer}
|
* by {@link WebAppInitializer} NB: modules are excluded from component scan since
|
||||||
* NB: modules are excluded from component scan since spring-context.xml sometimes holds important parameters and / or annotations
|
* spring-context.xml sometimes holds important parameters and / or annotations
|
||||||
|
*
|
||||||
* @author krylov
|
* @author krylov
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
@ -57,17 +48,19 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
"ervu_business_metrics"
|
"ervu_business_metrics"
|
||||||
}, excludeFilters = {
|
}, excludeFilters = {
|
||||||
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "security.WebSecurityConfig"),
|
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "security.WebSecurityConfig"),
|
||||||
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "ru.cg.webbpm.modules.database.impl.DatabaseConfiguration"),
|
@ComponentScan.Filter(type = FilterType.REGEX,
|
||||||
|
pattern = "ru.cg.webbpm.modules.database.impl.DatabaseConfiguration"),
|
||||||
})
|
})
|
||||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class AppConfig {
|
public class AppConfig {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
private static final Logger LOGGER = LoggerFactory.getLogger(
|
||||||
|
MethodHandles.lookup().lookupClass());
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(){
|
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||||
return new PropertySourcesPlaceholderConfigurer();
|
return new PropertySourcesPlaceholderConfigurer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,20 +87,12 @@ public class AppConfig {
|
||||||
createErvuMetricsSchema(dataSource);
|
createErvuMetricsSchema(dataSource);
|
||||||
liquibase.setDataSource(dataSource);
|
liquibase.setDataSource(dataSource);
|
||||||
liquibase.setChangeLog("classpath:config/changelog-master.xml");
|
liquibase.setChangeLog("classpath:config/changelog-master.xml");
|
||||||
liquibase.setChangeLogParameters(Collections.singletonMap("projectUser", getProjectDbUserName(dataSource)));
|
liquibase.setChangeLogParameters(
|
||||||
|
Collections.singletonMap("projectUser", getProjectDbUserName(dataSource)));
|
||||||
liquibase.setDefaultSchema("ervu_business_metrics");
|
liquibase.setDefaultSchema("ervu_business_metrics");
|
||||||
return liquibase;
|
return liquibase;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getProjectDbUserName(DataSource dataSource) {
|
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
|
||||||
return connection.getMetaData().getUserName();
|
|
||||||
}
|
|
||||||
catch (SQLException e) {
|
|
||||||
throw new AppInitializeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createErvuMetricsSchema(DataSource dataSource) {
|
private void createErvuMetricsSchema(DataSource dataSource) {
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
LOGGER.info("Start creating ervu_business_metrics schema");
|
LOGGER.info("Start creating ervu_business_metrics schema");
|
||||||
|
|
@ -128,6 +113,15 @@ public class AppConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getProjectDbUserName(DataSource dataSource) {
|
||||||
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
|
return connection.getMetaData().getUserName();
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
throw new AppInitializeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ObjectMapper objectMapper() {
|
public ObjectMapper objectMapper() {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue