diff --git a/Docs/context-datasource-convert.md b/Docs/context-datasource-convert.md index cd172c0..7cd6e13 100644 --- a/Docs/context-datasource-convert.md +++ b/Docs/context-datasource-convert.md @@ -1,36 +1,20 @@ -# context-datasource.xml 설정 변환 +# context-datasource.xml 설정 변환 > 데이터 소스관련 설정 사항들 다루고 있음 +## XML 설정 (기존) - -내장 DB 사용시 +### 내장 DB 사용시 ```xml - + ``` - - -```java -private DataSource dataSourceHSQL() { - return new EmbeddedDatabaseBuilder() - .setType(EmbeddedDatabaseType.HSQL) - .setScriptEncoding("UTF8") - .addScript("classpath:/db/shtdb.sql") - // .addScript("classpath:/otherpath/other.sql") - .build(); -} -``` - - - - -다른 DB 사용시 +### 다른 DB 사용시 @@ -50,54 +34,179 @@ private DataSource dataSourceHSQL() { +``` - - - - - - - +## Java Config 설정 (Globals 자동화 방식) + + + +```yaml +# 전자정부 프레임워크 글로벌 설정 (심플백엔드 호환) +# 주의: Globals.* 프로퍼티는 자동으로 PascalCase로 변환됩니다 +# 예시: Globals.db-type → Globals.DbType, Globals.mysql.driver-class-name → Globals.Mysql.DriverClassName +# 활용: propertiesService.getString("Globals.DbType") +# +# eGovFrame Global Configuration (Simple-backend compatible) +# Note: Globals.* properties are automatically converted to PascalCase +# Example: Globals.db-type → Globals.DbType, Globals.mysql.driver-class-name → Globals.Mysql.DriverClassName +# Usage: propertiesService.getString("Globals.DbType") +Globals: + # 데이터베이스 설정 + # Database settings + db-type: "mysql" # hsql, mysql, oracle + + # MySQL 설정 + # MySQL configuration + mysql: + driver-class-name: "com.mysql.cj.jdbc.Driver" + url: "jdbc:mysql://127.0.0.1:3306/egovframe" + user-name: "egovframe" + password: "egovframe" + + # Oracle 설정 + # Oracle configuration + oracle: + driver-class-name: "oracle.jdbc.driver.OracleDriver" + url: "jdbc:oracle:thin:@127.0.0.1:1521:XE" + user-name: "egovframe" + password: "egovframe" +``` - - - - - - - + - - - - - - - +```java +@Configuration +public class EgovConfigDatasource { + + @Autowired + private EgovPropertyService propertiesService; + + private String className; + private String url; + private String username; + private String password; + + /** + * 데이터소스 빈 생성 + * 프로퍼티 서비스에서 설정값을 읽어와 DB 타입에 따라 적절한 데이터소스 구성 + * @return DataSource 데이터소스 / DataSource instance + */ + @Bean(name="dataSource") + public DataSource dataSource() { + // 프로퍼티 서비스에서 DB 설정값 읽기 + // Read database configuration from property service + String dbType = propertiesService.getString("Globals.DbType", "hsql").toLowerCase(); + String dbTypeCapitalized = CaseUtils.toCamelCase(dbType, true); + this.className = propertiesService.getString("Globals." + dbTypeCapitalized + ".DriverClassName", "com.mysql.cj.jdbc.Driver"); + this.url = propertiesService.getString("Globals." + dbTypeCapitalized + ".Url", "jdbc:mysql://localhost:3306/egovframe"); + this.username = propertiesService.getString("Globals." + dbTypeCapitalized + ".UserName", "egovframe"); + this.password = propertiesService.getString("Globals." + dbTypeCapitalized + ".Password", "egovframe"); + + // DB 타입에 따른 데이터소스 생성 + // Create datasource based on database type + switch (dbType) { + case "mysql": + case "oracle": + return basicDataSource(dbType); + case "hsql": + default: + return embeddedDataSource(); + } + } + + /** + * 내장 데이터베이스 생성 (HSQL) + * @return DataSource 내장 데이터소스 / Embedded DataSource + */ + private DataSource embeddedDataSource() { + String scriptLocation = propertiesService.getString("Globals.Hsql.ScriptLocation", "classpath:/db/sampledb.sql"); + EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); + return builder + .setType(EmbeddedDatabaseType.HSQL) + .addScript(scriptLocation) + .build(); + } + + /** + * 외부 데이터베이스 생성 (MySQL, Oracle) + * @param dbType 데이터베이스 타입 / Database type + * @return DataSource 외부 데이터소스 / External DataSource + */ + private DataSource basicDataSource(String dbType) { + BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(this.className); + dataSource.setUrl(this.url); + dataSource.setUsername(this.username); + dataSource.setPassword(this.password); + + // 커넥션 풀 설정 + // Connection pool settings + dataSource.setInitialSize(5); + dataSource.setMaxTotal(20); + dataSource.setMaxIdle(10); + dataSource.setMinIdle(5); + return dataSource; + } +} ``` - +## 동적 프로퍼티 매핑 -```java +### DB 타입별 자동 프로퍼티 선택 -@PostConstruct -void init() { - dbType = env.getProperty("Globals.DbType"); - //Exception 처리 필요 - className = env.getProperty("Globals." + dbType + ".DriverClassName"); - url = env.getProperty("Globals." + dbType + ".Url"); - userName = env.getProperty("Globals." + dbType + ".UserName"); - password = env.getProperty("Globals." + dbType + ".Password"); -} +| DB 타입 | YAML 설정 | Java 프로퍼티 키 | +|---------|-----------|------------------| +| mysql | `Globals.mysql.driver-class-name` | `Globals.Mysql.DriverClassName` | +| mysql | `Globals.mysql.url` | `Globals.Mysql.Url` | +| oracle | `Globals.oracle.driver-class-name` | `Globals.Oracle.DriverClassName` | +| oracle | `Globals.oracle.url` | `Globals.Oracle.Url` | -...... +### 동작 방식 -private DataSource basicDataSource() { - BasicDataSource basicDataSource = new BasicDataSource(); - basicDataSource.setDriverClassName(className); - basicDataSource.setUrl(url); - basicDataSource.setUsername(userName); - basicDataSource.setPassword(password); - return basicDataSource; -} -``` \ No newline at end of file +1. **DB 타입 확인**: `Globals.DbType` 값 읽기 +2. **동적 키 생성**: `CaseUtils.toCamelCase(dbType, true)` 활용 +3. **프로퍼티 조회**: `Globals.{DbType}.{Property}` 형태로 자동 매핑 + +## 사용 예시 + +### HSQL (내장 DB) +```yaml +Globals: + db-type: "hsql" +``` +→ 내장 HSQL 데이터베이스 사용 + +### MySQL +```yaml +Globals: + db-type: "mysql" + mysql: + driver-class-name: "com.mysql.cj.jdbc.Driver" + url: "jdbc:mysql://localhost:3306/egovframe" + user-name: "egovframe" + password: "egovframe" +``` +→ MySQL 외부 데이터베이스 사용 + +### Oracle +```yaml +Globals: + db-type: "oracle" + oracle: + driver-class-name: "oracle.jdbc.driver.OracleDriver" + url: "jdbc:oracle:thin:@localhost:1521:XE" + user-name: "egovframe" + password: "egovframe" +``` +→ Oracle 외부 데이터베이스 사용 + +## 개선 효과 + +1. **심플백엔드 호환성**: Globals.* 구조로 기존 전자정부 프로젝트와 일관성 확보 +2. **동적 DB 지원**: DB 타입 변경만으로 자동 데이터소스 전환 +3. **프로퍼티 자동화**: YAML 설정만으로 DB 연결 정보 관리 +4. **커넥션 풀**: 외부 DB 사용 시 자동 커넥션 풀 설정 +5. **확장성**: 새로운 DB 타입 추가 시 YAML 설정만 추가 +6. **중앙 집중 관리**: 모든 DB 설정이 application.yml에서 관리 +7. **환경별 설정**: 개발/운영 환경별로 다른 DB 설정 가능 +8. **Docker 지원**: 컨테이너 환경에서의 DB 연동 최적화 diff --git a/Docs/context-properties-convert.md b/Docs/context-properties-convert.md index 2262063..16e1083 100644 --- a/Docs/context-properties-convert.md +++ b/Docs/context-properties-convert.md @@ -1,10 +1,10 @@ -# context-properties.xml 설정 변환 +# context-properties.xml 설정 변환 > 프로퍼티 정보 설정 +프로젝트 내에서 사용할 EgovPropertyService에 값을 등록하는 예제이다. - -프로젝트 내에서 사용할 EgovPropertyService에 값을 등록 하는 예제이다. +## XML 설정 (기존) @@ -22,21 +22,145 @@ ``` - +## Java Config 설정 (Globals 자동화 방식) + + + +```yaml +# 전자정부 프레임워크 글로벌 설정 (심플백엔드 호환) +# 주의: Globals.* 프로퍼티는 자동으로 PascalCase로 변환됩니다 +# 예시: Globals.page-unit → Globals.PageUnit, Globals.db-type → Globals.DbType +# 활용: propertiesService.getString("Globals.PageUnit") +# +# eGovFrame Global Configuration (Simple-backend compatible) +# Note: Globals.* properties are automatically converted to PascalCase +# Example: Globals.page-unit → Globals.PageUnit, Globals.db-type → Globals.DbType +# Usage: propertiesService.getString("Globals.PageUnit") +Globals: + # 페이징 설정 + # Pagination settings + page-unit: 10 + page-size: 10 + + # 파일 업로드 설정 + # File upload settings + posbl-atch-file-size: 5242880 + file-store-path: "./files" + added-options: false + + # 데이터베이스 설정 + # Database settings + db-type: "mysql" # hsql, mysql, oracle + + # MySQL 설정 + # MySQL configuration + mysql: + driver-class-name: "com.mysql.cj.jdbc.Driver" + url: "jdbc:mysql://127.0.0.1:3306/egovframe" + user-name: "egovframe" + password: "egovframe" + + # Oracle 설정 + # Oracle configuration + oracle: + driver-class-name: "oracle.jdbc.driver.OracleDriver" + url: "jdbc:oracle:thin:@127.0.0.1:1521:XE" + user-name: "egovframe" + password: "egovframe" +``` + + ```java -@Bean(destroyMethod = "destroy") -public EgovPropertyServiceImpl propertiesService() { - EgovPropertyServiceImpl egovPropertyServiceImpl = new EgovPropertyServiceImpl(); - - Map properties = new HashMap(); - properties.put("pageUnit", "10"); - properties.put("pageSize", "10"); - properties.put("posblAtchFileSize", "5242880"); - properties.put("Globals.fileStorePath", "/user/file/sht/"); - properties.put("Globals.addedOptions", "false"); - - egovPropertyServiceImpl.setProperties(properties); - return egovPropertyServiceImpl; +@Configuration +public class EgovConfigProperties { + + @Autowired + private Environment environment; + + @Bean(destroyMethod = "destroy") + public EgovPropertyServiceImpl propertiesService() { + EgovPropertyServiceImpl egovPropertyServiceImpl = new EgovPropertyServiceImpl(); + Map properties = new HashMap<>(); + + // 모든 프로퍼티 소스에서 Globals.* 프로퍼티를 찾아서 자동 변환 + // Find Globals.* properties from all property sources and convert automatically + MutablePropertySources propertySources = ((AbstractEnvironment) environment).getPropertySources(); + + for (PropertySource propertySource : propertySources) { + if (propertySource instanceof EnumerablePropertySource) { + String[] propertyNames = ((EnumerablePropertySource) propertySource).getPropertyNames(); + + for (String propertyName : propertyNames) { + if (propertyName.startsWith("Globals.")) { + String value = environment.getProperty(propertyName); + String key = convertGlobalsProperty(propertyName); + properties.put(key, value); + } + } + } + } + + egovPropertyServiceImpl.setProperties(properties); + return egovPropertyServiceImpl; + } + + // Globals.page-unit → Globals.PageUnit 변환 + // Globals.mysql.driver-class-name → Globals.Mysql.DriverClassName 변환 + private String convertGlobalsProperty(String propertyName) { + // CaseUtils.toCamelCase 활용한 변환 로직 + } } -``` \ No newline at end of file +``` + +## 자동 변환 예시 + +| YAML 설정 (kebab-case) | Java 프로퍼티 (PascalCase) | 설명 | +|------------------------|---------------------------|------| +| `Globals.page-unit` | `Globals.PageUnit` | 페이지당 항목 수 | +| `Globals.page-size` | `Globals.PageSize` | 페이지 크기 | +| `Globals.db-type` | `Globals.DbType` | 데이터베이스 타입 | +| `Globals.mysql.driver-class-name` | `Globals.Mysql.DriverClassName` | MySQL 드라이버 | +| `Globals.mysql.url` | `Globals.Mysql.Url` | MySQL 접속 URL | +| `Globals.oracle.user-name` | `Globals.Oracle.UserName` | Oracle 사용자명 | + +## 다중 데이터베이스 지원 + +### HSQL (내장 DB) +```yaml +Globals: + db-type: "hsql" +``` + +### MySQL +```yaml +Globals: + db-type: "mysql" + mysql: + driver-class-name: "com.mysql.cj.jdbc.Driver" + url: "jdbc:mysql://localhost:3306/egovframe" + user-name: "egovframe" + password: "egovframe" +``` + +### Oracle +```yaml +Globals: + db-type: "oracle" + oracle: + driver-class-name: "oracle.jdbc.driver.OracleDriver" + url: "jdbc:oracle:thin:@localhost:1521:XE" + user-name: "egovframe" + password: "egovframe" +``` + +## 개선 효과 + +1. **심플백엔드 호환성**: Globals.* 구조로 기존 전자정부 프로젝트와 일관성 확보 +2. **완전 자동화**: YAML에 프로퍼티만 추가하면 Java 코드 수정 없이 자동 등록 +3. **다중 DB 지원**: DB 타입에 따른 동적 데이터소스 생성 +4. **네이밍 컨벤션**: YAML은 kebab-case, Java는 PascalCase 자동 변환 +5. **중앙 집중 관리**: 모든 설정값이 application.yml에서 관리 +6. **환경별 설정**: 개발/운영 환경별로 다른 설정 파일 사용 가능 +7. **국제화**: 한글-영문 병행 주석으로 글로벌 개발자 지원 +8. **Apache Commons Text 활용**: 검증된 라이브러리로 안정적인 변환 diff --git a/README.md b/README.md index e395271..84dc603 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ __프로젝트 우클릭 > Run As > Spring Boot App__ 을 통해 구동한다. ### 구동 후 확인 구동 후, 브라우저에서 `http://localhost:포트번호/` 로 확인이 가능하다. -초기 포트번호는 8080이며 `src/main/resources/application.properties` 파일의 `server.port` 항목에서 변경 가능하다. +초기 포트번호는 8080이며 `src/main/resources/application.yml` 파일의 `server.port` 항목에서 변경 가능하다. ## 참조 화면 @@ -51,4 +51,61 @@ __프로젝트 우클릭 > Run As > Spring Boot App__ 을 통해 구동한다. #### 2) context-\*.xml -> @Configuration 변환 -#### 3) properties 변환(예정) boot 지원 +#### 3) properties 삭제 -> yaml 파일로 변환 + +--- + +# eGovFrame Boot-based Simple Board + +![java](https://img.shields.io/badge/java-007396?style=for-the-badge&logo=JAVA&logoColor=white) +![javascript](https://img.shields.io/badge/javascript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=black) +![Spring_boot](https://img.shields.io/badge/Spring_Boot-F2F4F9?style=for-the-badge&logo=spring-boot) +![maven](https://img.shields.io/badge/Maven-C71A36?style=for-the-badge&logo=apache-maven&logoColor=white) +![workflow](https://github.com/eGovFramework/egovframe-boot-sample-java-config/actions/workflows/maven.yml/badge.svg) + +※ This project is a basic board example source code based on Spring Boot. + +## Environment Setup + +The environment program information used in the project is as follows. +| Program Name | Version | +| :--------- | :------ | +| java | 1.8 or higher | +| maven | 3.8.4 ~ 3.8.8 | + +## Project Execution + +### CLI Execution Method + +```bash +mvn spring-boot:run +``` + +### IDE Execution Method + +Execute through __Project Right Click > Run As > Spring Boot App__. + +### Verification After Execution + +After execution, you can check at `http://localhost:port number/` in the browser. +The initial port number is 8080, and it can be changed in the `server.port` item of the `src/main/resources/application.yml` file. + +## Reference Screens + +### List Screen + +![4th_new_web4](https://github.com/user-attachments/assets/199c6964-1aa1-42bc-a3d2-0234d037057a) + +### Post Registration Screen + +![4th_new_web5](https://github.com/user-attachments/assets/91c1b668-cb59-45ea-8b13-0e3f34ea9078) + +## Changes + +### 1. [Java Config Conversion](./Docs/java-config-convert.md) + +#### 1) Web.xml -> WebApplicationInitializer Implementation Conversion + +#### 2) context-\*.xml -> @Configuration Conversion + +#### 3) properties Deletion -> yaml File Conversion diff --git a/pom.xml b/pom.xml index 1d92a99..aee1784 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,23 @@ 2.7.3 jdk8 + + com.mysql + mysql-connector-j + 8.4.0 + + + + org.apache.commons + commons-dbcp2 + 2.12.0 + org.projectlombok lombok diff --git a/src/main/java/egovframework/example/config/EgovConfigDatasource.java b/src/main/java/egovframework/example/config/EgovConfigDatasource.java index 6dd7068..618a9fc 100644 --- a/src/main/java/egovframework/example/config/EgovConfigDatasource.java +++ b/src/main/java/egovframework/example/config/EgovConfigDatasource.java @@ -1,5 +1,9 @@ package egovframework.example.config; +import org.apache.commons.dbcp2.BasicDataSource; +import org.apache.commons.text.CaseUtils; +import org.egovframe.rte.fdl.property.EgovPropertyService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; @@ -7,13 +11,92 @@ import javax.sql.DataSource; +/** + * 전자정부 프레임워크 데이터소스 설정 + * eGovFrame DataSource Configuration + * + * @author eGovFrame Development Team + * @since 2025.09.17 + * @version 4.3.1 + */ @Configuration public class EgovConfigDatasource { + @Autowired + private EgovPropertyService propertiesService; + + private String className; + private String url; + private String username; + private String password; + + /** + * 데이터소스 빈 생성 + * 프로퍼티 서비스에서 설정값을 읽어와 DB 타입에 따라 적절한 데이터소스 구성 + * - + * Create DataSource bean + * Configure appropriate datasource based on database type from property service + * + * @return DataSource 데이터소스 / DataSource instance + */ @Bean(name="dataSource") public DataSource dataSource() { - EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); - return builder.setType(EmbeddedDatabaseType.HSQL).addScript("classpath:/db/sampledb.sql").build(); + // 프로퍼티 서비스에서 DB 설정값 읽기 + // Read database configuration from property service + String dbType = propertiesService.getString("Globals.DbType", "mysql").toLowerCase(); + String dbTypeCapitalized = CaseUtils.toCamelCase(dbType, true); + this.className = propertiesService.getString("Globals." + dbTypeCapitalized + ".DriverClassName", "com.mysql.cj.jdbc.Driver"); + this.url = propertiesService.getString("Globals." + dbTypeCapitalized + ".Url", "jdbc:mysql://localhost:3306/egovframe"); + this.username = propertiesService.getString("Globals." + dbTypeCapitalized + ".UserName", "sa"); + this.password = propertiesService.getString("Globals." + dbTypeCapitalized + ".Password", "egovframe"); + + // DB 타입에 따른 데이터소스 생성 + // Create datasource based on database type + switch (dbType) { + case "mysql": + case "oracle": + return basicDataSource(dbType); + case "hsql": + default: + return embeddedDataSource(); + } } + /** + * 내장 데이터베이스 생성 (HSQL) + * Create embedded database (HSQL) + * + * @return DataSource 내장 데이터소스 / Embedded DataSource + */ + private DataSource embeddedDataSource() { + String scriptLocation = propertiesService.getString("Globals.Hsql.ScriptLocation", "classpath:/db/sampledb.sql"); + EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); + return builder + .setType(EmbeddedDatabaseType.HSQL) + .addScript(scriptLocation) + .build(); + } + + /** + * 외부 데이터베이스 생성 (MySQL, Oracle) + * Create external database (MySQL, Oracle) + * + * @param dbType 데이터베이스 타입 / Database type + * @return DataSource 외부 데이터소스 / External DataSource + */ + private DataSource basicDataSource(String dbType) { + BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(this.className); + dataSource.setUrl(this.url); + dataSource.setUsername(this.username); + dataSource.setPassword(this.password); + + // 커넥션 풀 설정 + // Connection pool settings + dataSource.setInitialSize(5); + dataSource.setMaxTotal(20); + dataSource.setMaxIdle(10); + dataSource.setMinIdle(5); + return dataSource; + } } diff --git a/src/main/java/egovframework/example/config/EgovConfigProperties.java b/src/main/java/egovframework/example/config/EgovConfigProperties.java index e0b22ae..17281dd 100644 --- a/src/main/java/egovframework/example/config/EgovConfigProperties.java +++ b/src/main/java/egovframework/example/config/EgovConfigProperties.java @@ -1,24 +1,105 @@ package egovframework.example.config; +import org.apache.commons.text.CaseUtils; import org.egovframe.rte.fdl.property.impl.EgovPropertyServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.AbstractEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; import java.util.HashMap; import java.util.Map; +/** + * 전자정부 프레임워크 프로퍼티 서비스 설정 + * eGovFrame Property Service Configuration + * + * @author eGovFrame Development Team + * @since 2025.09.17 + * @version 4.3.1 + */ @Configuration public class EgovConfigProperties { + @Autowired + private Environment environment; + + /** + * 전자정부 프레임워크 프로퍼티 서비스 빈 생성 + * YAML 설정 파일에서 Globals.* 프로퍼티를 자동으로 읽어와 PascalCase로 변환하여 등록 + * - + * Create eGovFrame property service bean + * Automatically read Globals.* properties from YAML configuration and convert to PascalCase + * + * @return EgovPropertyServiceImpl 프로퍼티 서비스 구현체 / Property service implementation + */ @Bean(destroyMethod="destroy") public EgovPropertyServiceImpl propertiesService() { + EgovPropertyServiceImpl egovPropertyServiceImpl = new EgovPropertyServiceImpl(); Map properties = new HashMap<>(); - properties.put("pageUnit", "10"); - properties.put("pageSize", "10"); + + // 모든 프로퍼티 소스에서 Globals.* 프로퍼티를 찾아서 자동 변환 + // Find Globals.* properties from all property sources and convert automatically + MutablePropertySources propertySources = ((AbstractEnvironment) environment).getPropertySources(); + + for (PropertySource propertySource : propertySources) { + if (propertySource instanceof EnumerablePropertySource) { + String[] propertyNames = ((EnumerablePropertySource) propertySource).getPropertyNames(); + + for (String propertyName : propertyNames) { + if (propertyName.startsWith("Globals.")) { + String value = environment.getProperty(propertyName); + + // Globals. 접두사 유지하고 나머지 부분을 kebab-case → PascalCase로 변환 + // Keep Globals. prefix and convert remaining part from kebab-case to PascalCase + String key = convertGlobalsProperty(propertyName); + + properties.put(key, value); + } + } + } + } - EgovPropertyServiceImpl egovPropertyServiceImpl = new EgovPropertyServiceImpl(); egovPropertyServiceImpl.setProperties(properties); return egovPropertyServiceImpl; } + /** + * Globals 프로퍼티 키를 PascalCase로 변환 + * Convert Globals property key to PascalCase + * Example : Globals.page-unit → Globals.PageUnit + * Example : Globals.mysql.driver-class-name → Globals.Mysql.DriverClassName + * + * @param propertyName 원본 프로퍼티 이름 / Original property name + * @return String 변환된 프로퍼티 이름 / Converted property name + */ + private String convertGlobalsProperty(String propertyName) { + // Globals. 접두사 분리 + // Separate Globals. prefix + String withoutGlobals = propertyName.substring(8); // "Globals." 제거 + + // 점(.)으로 분할하여 각 부분을 PascalCase로 변환 + // Split by dot and convert each part to PascalCase + String[] parts = withoutGlobals.split("\\."); + StringBuilder result = new StringBuilder("Globals."); + + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + // kebab-case를 PascalCase로 변환 (첫글자 대문자) + // Convert kebab-case to PascalCase (first letter uppercase) + String pascalCase = CaseUtils.toCamelCase(part, true, '-'); + result.append(pascalCase); + + if (i < parts.length - 1) { + result.append("."); + } + } + + return result.toString(); + } + } diff --git a/src/main/java/egovframework/example/sample/web/EgovSampleController.java b/src/main/java/egovframework/example/sample/web/EgovSampleController.java index f07517a..648ae4d 100644 --- a/src/main/java/egovframework/example/sample/web/EgovSampleController.java +++ b/src/main/java/egovframework/example/sample/web/EgovSampleController.java @@ -33,8 +33,8 @@ public String search(@ModelAttribute SampleVO sampleVO, Model model) throws Exce @PostMapping("/sample/list") public String list(@ModelAttribute SampleVO sampleVO, Model model) throws Exception { - sampleVO.setPageUnit(propertiesService.getInt("pageUnit")); - sampleVO.setPageSize(propertiesService.getInt("pageSize")); + sampleVO.setPageUnit(propertiesService.getInt("Globals.PageUnit")); + sampleVO.setPageSize(propertiesService.getInt("Globals.PageSize")); // pagination setting PaginationInfo paginationInfo = new PaginationInfo(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 3b59fc5..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,9 +0,0 @@ -server.port=8080 - -# \uc218\ub3d9 Bean\uc774 \uc790\ub3d9 Bean\uc744 \uc624\ubc84\ub77c\uc774\ub529\ud558\uac8c \uc124\uc815 -spring.main.allow-bean-definition-overriding=true - -# open-in-view(\ud639\uc740 Open-Session-In-View(OSIV)) -# true(\uae30\ubcf8\uac12) : \uc0ac\uc6a9\uc790\uc5d0\uac8c \uc751\ub2f5 \ub610\ub294 view\uac00 \ub80c\ub354\ub9c1\ub420 \ub54c\uae4c\uc9c0 \uc601\uc18d\uc131 \ucee8\ud14d\uc2a4\ud2b8 \uc720\uc9c0 -# false : \ud2b8\ub79c\uc81d\uc158\uc774 \uc885\ub8cc\ub420 \ub54c \uc601\uc18d\uc131 \ucee8\ud14d\uc2a4\ud2b8 \uc885\ub8cc -spring.jpa.open-in-view=false diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..323bf8f --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,71 @@ +# 전자정부 표준프레임워크 Spring Boot 설정 +# eGovFrame Spring Boot Configuration + +server: + # 서버 포트 설정 + # Server port configuration + port: 8080 + +spring: + main: + # 수동 Bean이 자동 Bean을 오버라이딩하게 설정 + # 개발 시 커스텀 Bean이 기본 Bean을 대체할 수 있도록 허용 + # Allow manual beans to override automatic beans + # Enables custom beans to replace default beans during development + allow-bean-definition-overriding: true + + jpa: + # Open-in-View 패턴 설정 (OSIV) + # true(기본값): 사용자에게 응답 또는 view가 렌더링될 때까지 영속성 컨텍스트 유지 + # false: 트랜잭션이 종료될 때 영속성 컨텍스트 종료 (성능상 권장) + # + # Open-in-View pattern configuration (OSIV) + # true(default): Keep persistence context until response or view rendering to user + # false: Close persistence context when transaction ends (recommended for performance) + open-in-view: false + +# 전자정부 프레임워크 글로벌 설정 (심플백엔드 호환) +# 주의: Globals.* 프로퍼티는 자동으로 camelCase로 변환됩니다 +# 예시: Globals.page-unit → Globals.PageUnit, Globals.db-type → Globals.DbType +# 활용: propertiesService.getString("Globals.PageUnit") +# +# eGovFrame Global Configuration (Simple-backend compatible) +# Note: Globals.* properties are automatically converted to camelCase +# Example: Globals.page-unit → Globals.PageUnit, Globals.db-type → Globals.DbType +# Usage: propertiesService.getString("Globals.PageUnit") +Globals: + # 페이징 설정 + # Pagination settings + page-unit: 10 + page-size: 10 + + # 파일 업로드 설정 + # File upload settings + posbl-atch-file-size: 5242880 + file-store-path: "./files" + added-options: false + + # 데이터베이스 설정(hsql,mysql,oracle) + # Database settings + db-type: "hsql" + + # HSQL 설정 + # HSQL configuration + hsql: + script-location: "classpath:/db/sampledb.sql" + + # MySQL 설정 + # MySQL configuration + mysql: + driver-class-name: "com.mysql.cj.jdbc.Driver" + url: "jdbc:mysql://127.0.0.1:3306/egovframe" + user-name: "egovframe" + password: "egovframe" + + # Oracle 설정 + # Oracle configuration + oracle: + driver-class-name: "oracle.jdbc.driver.OracleDriver" + url: "jdbc:oracle:thin:@127.0.0.1:1521:sampledb" + user-name: "sa" + password: "" \ No newline at end of file