You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.7 KiB
Java

package cokr.xit.custom.boot;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.egovframe.rte.fdl.cmmn.trace.LeaveaTrace;
import org.egovframe.rte.fdl.property.impl.EgovPropertyServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.databind.ObjectMapper;
@Configuration
@ComponentScan(basePackages = {"cokr.xit",
"externalsystem.sinmungo",
"externalsystem.nxrp",
"externalsystem.piss",
"externalsystem.ino",
"externalsystem.jinwoo",
"externalsystem.nuri2"
})
public class CommonConfig {
/**AntPathMatcher를 반환한다.
* @return AntPathMatcher
*/
@Bean
public AntPathMatcher antPathMatcher() {
return new AntPathMatcher();
}
/**ObjectMapper를 반환한다.
* @return ObjectMapper
*/
@Bean
public ObjectMapper objectMapper() {
ObjectMapper bean = new ObjectMapper();
bean.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
bean.configure(Feature.ALLOW_COMMENTS, true);
return bean;
}
/**SessionLocaleResolver를 반환한다.
* @return SessionLocaleResolver
*/
@Bean
public SessionLocaleResolver localeResolver() {
SessionLocaleResolver bean = new SessionLocaleResolver();
bean.setDefaultLocale(Locale.getDefault());
return bean;
}
/**LeaveaTrace를 반환한다.
* @return LeaveaTrace
*/
@Bean
public LeaveaTrace leaveaTrace() {
return new LeaveaTrace();
}
private Yml yml = new Yml("application.yml", "application.yml");
/**application.yml의 설정 내용을 읽어 MessageSource Bean을 설정하여 반환한다.
* <pre><code> messageSource:
* basenames:
* - classpath:message/message-common
* - classpath:message/authentication-message
* - classpath:org/egovframe/rte/fdl/property/messages/properties</code></pre>
* @return ReloadableResourceBundleMessageSource
*/
@Bean
public ReloadableResourceBundleMessageSource messageSource() {
ReloadableResourceBundleMessageSource bean = new ReloadableResourceBundleMessageSource();
bean.setDefaultEncoding("UTF-8");
bean.setCacheSeconds(60);
List<String> basenames = yml.getValues("messageSource.basenames");
if (!basenames.isEmpty())
bean.setBasenames(basenames.toArray(new String[basenames.size()]));
return bean;
}
/**application.yml의 설정 내용을 읽어 EgovPropertyServiceImpl Bean을 설정하여 반환한다.
* <pre><code> propertyService:
* properties: # 인라인 프로퍼티가 있을 경우
* - property0: value0
* - property1: value1
* extFileName: #외부 프로퍼티 파일이 있을 경우
* - encoding: UTF-8
* filename: classpath*:properties/your-file-01.properties
* - encoding: UTF-8
* filename: classpath*:properties/your-file-02.properties</code></pre>
* @return EgovPropertyServiceImpl
*/
@Bean
public EgovPropertyServiceImpl propertyService() {
EgovPropertyServiceImpl bean = new EgovPropertyServiceImpl();
Map<String, String> properties = yml.getMap("propertyService.properties");
if (!properties.isEmpty())
bean.setProperties(properties);
Set<?> filenames = yml.getMaps("propertyService.extFileName").stream().collect(Collectors.toSet());
if (!filenames.isEmpty())
bean.setExtFileName(filenames);
return bean;
}
}