com.quincy.core.CommonApplicationContext Maven / Gradle / Ivy
package com.quincy.core;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import com.quincy.sdk.Constants;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Configuration
//@Order(1)
public class CommonApplicationContext {//implements TransactionManagementConfigurer {
@Bean
public MessageSource messageSource() throws IOException {
Map map = new HashMap();
new ClassPathHandler() {
@Override
protected void run(List resources) {
for(int i=0;i resourceList = new ArrayList();
new ClassPathHandler() {
@Override
protected void run(List resources) {
resourceList.addAll(resources);
}
}.start("classpath*:application.properties", "classpath*:application-*.properties");
Resource[] locations = new Resource[resourceList.size()];
locations = resourceList.toArray(locations);
PropertiesFactoryBean bean = new PropertiesFactoryBean();
bean.setLocations(locations);
bean.afterPropertiesSet();
log.warn("====================PROPERTIES_FACTORY_BEAN_CREATED");
return bean;
}
private abstract class ClassPathHandler {
protected abstract void run(List resources);
public void start(String... locationPatterns) throws IOException {
PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver();
List resourceList = new ArrayList(50);
for(String locationPattern:locationPatterns) {
Resource[] resources = r.getResources(locationPattern);
for(Resource resource:resources) {
resourceList.add(resource);
}
}
this.run(resourceList);
}
}
@PostConstruct
public void init() {
log.warn("====================COMMON_INITED");
}
}