Merge remote-tracking branch 'origin/main'

dev
kjh 6 months ago
commit 8475210426

@ -1,113 +0,0 @@
package cokr.xit.foundation.boot;
import java.text.SimpleDateFormat;
import java.util.List;
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.core.env.Environment;
import org.springframework.util.AntPathMatcher;
import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.databind.ObjectMapper;
/** xit foundation Bean .
* @author mjkhan
*/
@Configuration
@ComponentScan(basePackages = "cokr.xit")
public class CommonConfig {
final Environment env;
public CommonConfig(Environment env) {
this.env = env;
}
/**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;
}
/**LeaveaTrace .
* @return LeaveaTrace
*/
@Bean
public LeaveaTrace leaveaTrace() {
return new LeaveaTrace();
}
//private Yml yml = new Yml("application.yml", "application.yml", env);
@Bean
public Yml yml() {
return new Yml("application.yml", "application.yml", env);
}
/**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;
}
}

@ -1,148 +0,0 @@
package cokr.xit.foundation.boot;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.boot.env.YamlPropertySourceLoader;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource;
import cokr.xit.foundation.Assert;
/**yml .
* <p>
* @author mjkhan
*/
public class Yml {
private Map<String, ?> source;
private final Environment env;
/** Yml .
* @param rootName
* @param path yml
*/
public Yml(String rootName, String path, Environment environment) {
this.env = environment;
load(rootName, path);
}
/** yml .
* @param rootName
* @param path yml
* @return Yml
*/
public Yml load(String rootName, String path) {
source = null;
try {
List<PropertySource<?>> sources = new YamlPropertySourceLoader()
.load(rootName, new ClassPathResource(path));
if (!sources.isEmpty()) {
source = (Map<String, ?>)sources.get(0).getSource();
}
// Spring-boot profile별 설정이 있는 경우 처리
String[] activeProfiles = env.getActiveProfiles();
for (String profile : activeProfiles) {
PropertySource<?> profileSource = sources.stream()
.filter(ps -> ps.getName().equals(profile))
.findFirst()
.orElse(null); // default to null if no matching profile is found
if (profileSource != null) {
// Merge the properties of the profile into the source map
((Map<String, Object>)source).putAll((Map<String, ?>)profileSource.getSource());
}
}
return this;
} catch (Exception e) {
throw Assert.runtimeException(e);
}
}
/** ( ) .
* @param key .
* <pre><code> spring:
* application:
* name: my-application
* </code></pre>
* @return
*/
public String getValue(String key) {
if (source == null) return "";
Object obj = source.get(key);
return obj != null ? obj.toString() : "";
}
/** ( ) .
* <pre><code> list:
* - item-0
* - item-2
* - item-3</code></pre>
* @param prefix
* @return
*/
public List<String> getValues(String prefix) {
if (source == null) return Collections.emptyList();
return getPrefixed(prefix).stream()
.map(entry -> entry.getValue().toString())
.collect(Collectors.toList());
}
private List<Map.Entry<String, ?>> getPrefixed(String prefix) {
return source.entrySet().stream()
.filter(entry -> entry.getKey().startsWith(prefix))
.collect(Collectors.toList());
}
/** ( ) Map .
* <pre><code> parent:
* - property-0: value-0
* - property-1: value-1
* - property-2: value-2</code></pre>
* @param prefix
* @return Map
*/
public Map<String, String> getMap(String prefix) {
if (source == null) return Collections.emptyMap();
LinkedHashMap<String, String> map = new LinkedHashMap<>();
getPrefixed(prefix).stream().forEach(entry -> putTo(map, entry));
return map;
}
private void putTo(LinkedHashMap<String, String> map, Map.Entry<String, ?> entry) {
String key = entry.getKey();
key = key.substring(key.lastIndexOf(".") + 1);
String val = entry.getValue().toString();
map.put(key, val);
}
/** ( ) Map .
* <pre><code> parent:
* - property-0: value-0.0
* property-1: value-0.1
* - property-0: value-1.0
* property-1: value-1.1</code></pre>
* @param prefix
* @return Map
*/
public List<Map<String, String>> getMaps(String prefix) {
if (source == null) return Collections.emptyList();
return getPrefixed(prefix).stream()
.map(entry -> {
String str = entry.getKey();
return str.substring(0, str.lastIndexOf("."));
})
.collect(Collectors.toSet()).stream()
.map(this::getMap)
.collect(Collectors.toList());
}
}

@ -21,14 +21,6 @@ spring:
init: init:
platform: mariadb platform: mariadb
datasource:
hikari:
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
jdbc-url: jdbc:log4jdbc:mariadb://211.119.124.9:4407/adds?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul&useSSL=false
username: addsweb
password: addsweb1234
auto-commit: false
mvc: mvc:
static-path-pattern: /resources/**,/files/** static-path-pattern: /resources/**,/files/**
web: web:
@ -59,6 +51,18 @@ spring:
activate: activate:
on-profile: local on-profile: local
datasource:
hikari:
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
jdbc-url: jdbc:log4jdbc:mariadb://211.119.124.9:4407/adds?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul&useSSL=false
username: addsweb
password: addsweb1234
auto-commit: false
propertyService:
properties:
- tempDir: C:\temppp
app: app:
api: api:
host: http://localhost:9076 host: http://localhost:9076
@ -69,6 +73,21 @@ spring:
activate: activate:
on-profile: prod on-profile: prod
datasource:
hikari:
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
jdbc-url: jdbc:log4jdbc:mariadb://211.119.124.9:4407/adds?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul&useSSL=false
username: addsweb
password: addsweb1234
auto-commit: false
server:
port: 9077
propertyService:
properties:
- tempDir: C:\temp
app: app:
api: api:
host: http://localhost:9076 host: http://localhost:9076

Loading…
Cancel
Save