Skip to content

Instantly share code, notes, and snippets.

@Macadoshis
Created November 28, 2018 11:55
Show Gist options
  • Save Macadoshis/9d02acd6de1036ee43006416d210f249 to your computer and use it in GitHub Desktop.
Save Macadoshis/9d02acd6de1036ee43006416d210f249 to your computer and use it in GitHub Desktop.
package ch.vd.dfin.taopm.web.config;
import static ch.vd.dfin.taopm.web.config.TaoPMSpringBootApplication.CLASSPATH_APPLICATION_PROPERTIES;
import static ch.vd.dfin.taopm.web.config.TaoPMSpringBootApplication.FILE_ENVIRONMENT_PROPERTIES;
import java.util.Arrays;
import java.util.Collection;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
import org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.logging.LoggingApplicationListener;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.context.WebApplicationContext;
import ch.vd.dfin.tao.business.spring.TaoCoreBusinessConfig;
import ch.vd.dfin.tao.business.utils.TaoAsyncUtils;
import ch.vd.dfin.tao.core.communication.spring.TaoCoreCommunicationSpringConfig;
import ch.vd.dfin.tao.core.engine.spring.TaoCoreEngineSpringConfig;
import ch.vd.dfin.tao.core.enrichissement.spring.TaoEchEnrichissementSpringConfig;
import ch.vd.dfin.tao.core.impl.spring.TaoCoreSpringConfig;
import ch.vd.dfin.tao.core.impl.utils.cache.LoadMethodesCacheApplicationListener;
import ch.vd.dfin.tao.core.web.spring.TaoCoreWebSpringConfig;
import ch.vd.dfin.tao.core.web.utils.context.TaoServletEnvironment;
import ch.vd.dfin.tao.core.web.utils.context.TaoSpringBootApplication;
import ch.vd.dfin.taopm.business.spring.TaoBusinessSpringConfig;
import ch.vd.dfin.taopm.dao.spring.TaoDaoSpringConfig;
import ch.vd.dfin.taopm.echange.entrant.spring.TaoEchEntrantSpringConfig;
import ch.vd.dfin.taopm.echange.sortant.spring.TaoEchSortantSpringConfig;
import ch.vd.dfin.taopm.engine.spring.TaoEngineSpringConfig;
import ch.vd.dfin.taopm.services.spring.TaoServicesSpringConfig;
import ch.vd.dfin.taopm.web.config.async.TaoPmRifdAsyncUtilsFactory;
import ch.vd.dfin.taopm.web.config.filters.TaoDataSourceRoutingFilter;
import ch.vd.dfin.taopm.web.spring.TaoWebSpringConfig;
@SpringBootApplication
// same as @Configuration @EnableAutoConfiguration @ComponentScan
@ImportResource({"classpath:tao-exchange-web-services-beans.xml", "classpath:tao-exchange-services-beans.xml", "classpath:tao-exchange-validation-beans.xml",
"classpath:tao-exchange-esb-beans.xml",
// TODO GDO : exporter la configuration applicative (déclarer nouveaux beans + alias sur beans à overrider)
"classpath:tao-exchange-jmx-beans.xml", "classpath:taopm-exchange-endpoint-beans.xml"})
@Import({
// Spring/Core
RepositoryRestMvcConfiguration.class,
// tao-core
TaoCoreSpringConfig.class, TaoCoreCommunicationSpringConfig.class, TaoCoreBusinessConfig.class, TaoCoreEngineSpringConfig.class, TaoEchEnrichissementSpringConfig.class,
TaoCoreWebSpringConfig.class,
// tao-pm
TaoEchSortantSpringConfig.class, TaoEchEntrantSpringConfig.class, TaoDaoSpringConfig.class, TaoBusinessSpringConfig.class, TaoEngineSpringConfig.class,
TaoServicesSpringConfig.class, TaoWebSpringConfig.class})
@EnableTransactionManagement(order = 3)
@EnableAspectJAutoProxy
@EnableAutoConfiguration(exclude = {VelocityAutoConfiguration.class, LoggingApplicationListener.class, BatchAutoConfiguration.class})
@ComponentScan(basePackages = {
// tao-exchange
"ch.vd.dfin.tao.exchange"})
@EnableJpaRepositories(basePackages = {
// tao-exchange
"ch.vd.dfin.tao.exchange.service"})
// les @EntityScan ne peuvent être importés depuis les config de @Import
@EntityScan(basePackages = {
// tao-exchange
"ch.vd.dfin.tao.exchange",
// tao-core
"ch.vd.dfin.tao.core.communication.env.model", "ch.vd.dfin.tao.core.impl.model", "ch.vd.dfin.tao.core.engine.model.reference",
"ch.vd.dfin.tao.core.impl.enumeration.usertype", "ch.vd.dfin.tao.core.engine.enumeration.usertype",
// tao-pm
"ch.vd.dfin.taopm.metier.model.dao", "ch.vd.dfin.taopm.dao.usertypes",
// tao-rifd
"ch.vd.dfin.taorifd.metier.model.dao", "ch.vd.dfin.taorifd.dao.usertypes"})
@PropertySources({@PropertySource(CLASSPATH_APPLICATION_PROPERTIES),
@PropertySource(value = "file:${ch.vd.appDir}/tao-pm/config/application.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:${ch.vd.appDir}/tao-pm/config/tao-rifd/application.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:${ch.vd.appDir}/tao-pm/config/credentials.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:${ch.vd.appDir}/tao-pm/config/tao-rifd/credentials.properties", ignoreResourceNotFound = true),
@PropertySource(value = FILE_ENVIRONMENT_PROPERTIES, ignoreResourceNotFound = true),
@PropertySource(value = "file:${ch.vd.appDir}/tao-pm/config/tao-rifd/environment.properties", ignoreResourceNotFound = true)})
public class TaoPMSpringBootApplication extends TaoSpringBootApplication {
static final String CLASSPATH_APPLICATION_PROPERTIES = "classpath:/application.properties";
static final String FILE_ENVIRONMENT_PROPERTIES = "file:${ch.vd.appDir}/tao-pm/config/environment.properties";
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
final TaoServletEnvironment environment = new TaoServletEnvironment() {
@Override
protected Collection<String> getPathsPropertiesFiles() {
return Arrays.asList(CLASSPATH_APPLICATION_PROPERTIES, FILE_ENVIRONMENT_PROPERTIES);
}
};
addSpringProfiles(environment,
// Environnement
"environment.profile",
// Service UNIREG
"unireg.ws.profile",
// Simuler la queue esb Editique (esbEditiqueBouchon ou vide)
"esb.editique.profile",
// Mode de gestion des tables techniques de spring-batch
"spring.batch.techtables.profile");
application.environment(environment);
// Positionne le gestionnaire asynchrone par défaut
TaoAsyncUtils.setDefaultTaoAsyncUtilsFactory(TaoPmRifdAsyncUtilsFactory.class);
return application
// Affichage de la banner
.showBanner(true)
// Context Spring-Boot parent (principal)
.sources(TaoPMSpringBootApplication.class);
}
@Override
protected LoadMethodesCacheApplicationListener getLoadMethodesCacheApplicationListener(WebApplicationContext webApplicationContext) {
return new TaoPMLoadMethodesCacheApplicationListener(webApplicationContext);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.addFilter("dsRoutingFilter", new TaoDataSourceRoutingFilter()).addMappingForUrlPatterns(null, false, "/*");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment