Spring Boot에서 application.yml 파일은 Application 설정을 정의하는 YAML 형식의 파일이며 Spring Boot는 이 파일을 기반으로 Application을 실행합니다. msp-gw-boot-web/src/main/resources 경로에서 application.yml 파일을 확인할 수 있습니다.
server:
port: 28080
servlet:
encoding:
charset: UTF-8
enabled: true
force: true
context-path: /msp-gw
logging:
level:
root: info
org.springdoc: info
org.springframework: info
kr.msp: trace
database: oracle
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
messages:
basename: message/messages
# datasource:
# jndi-name: jdbc/msp_oracle
# driver-class-name: oracle.jdbc.OracleDriver
# url: jdbc:oracle:thin:@127.0.0.1:1521:UDB
# username: lab
# password: lab
#mybatis:
# mapper-locations: classpath:/sqlmap/${database}/**/*.xml
# configuration:
# map-underscore-to-camel-case: true
# H2 property
# sql:
# init:
# schema-locations: classpath:${database}/schema.sql
# data-locations: classpath:${database}/data.sql
# mode: always
# h2:
# console:
# enabled: true
# settings:
# web-allow-others: true
msp:
gateway:
datasource:
# jndi-name: jdbc/msp_oracle
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@127.0.0.11521:UDB
username: lab
password: lab
mybatis:
# mapper-locations: classpath:/sqlmap/${database}/**/*.xml
platform: oracle
resource-update:
use-force-https: true
https-port: 443
download-url:
download-type: filename
event-log:
path: /Users/uracle/temp/log/msp-gw/eventlogs/
enabled: true
cron: 0 0/1 * * * ?
app-store:
service-path: http://127.0.0.1/msp-admin/
bin-path: apk
upload-path: /apps/msp-admin/
file:
upload:
location: /Users/uracle/temp/trash/upload
http:
server:
url: http://localhost:9090
legacy:
url: http://localhost:28080/msp-gw/api/file/download/
download: /Users/uracle/temp/trash/download/
주요 섹션 설명
애플리케이션에서 직접 데이터베이스 연결정보를 설정하여 사용하는 방식입니다. 지원하는 DBMS는 oracle, mysql, mssql, db2, informix, oracle9i, postgresql이며, 각 DBMS에 해당하는 driver-class-name
및 url
은 아래와 같습니다.
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@localhost:1521/XE
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost:1433;databaseName=test
driver-class-name: com.ibm.db2.jcc.DB2Driver
url: jdbc:db2://localhost:50000/test
driver-class-name: com.informix.jdbc.IfxDriver
url: jdbc:informix-sqli://localhost:9088/test:informixserver=ol_informix
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/test
아래의 예시는 oracle을 연결하는 예시입니다.
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>21.9.0.0</version>
</dependency>
Note: mapper 경로는 sqlmap/**/**/*.xml 형식으로, 변경하지 않도록 주의합니다.
database: oracle
msp:
gateway:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@localhost:1521/XE
username: my_username
password: my_password
mybatis:
mapper-locations: classpath:/sqlmap/${database}/**/*.xml
msp.gateway.datasource에 DB연결을 정의하면, msp-gateway 라이브러리에 있는 GatewayMybatisConfiguration 클래스에 의해 자동으로 Mybatis를 위한 SqlSessionFactory와 SqlSessionTemplate 설정이 진행됩니다. Mapper camel-case 옵션은 default로 설정되어 있습니다.
아래의 예시는 H2를 연결하는 예시입니다.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
msp:
gateway:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=Oracle
username: sa
password:
mybatis:
platform: oracle
DataSourceInitializerConfiguration.java : 해당 클래스는 어플리케이션 시작 시, 데이터베이스를 초기화 하는 역할을 합니다.
SqlDataSourceScriptDatabaseInitializer의 인스턴스를 생성하고, 스키마 및 데이터 초기화를 위한 SQL 스크립트 위치를 지정하기 위해 SqlInitializationProperties 객체를 생성합니다. schemaLocation을 classpath:schema.sql로 설정, dataLocation을 classpath:data.sql로 설정합니다. 해당 파일들은 어플리케이션 클래스패스 내에 있음을 나타냅니다.
@Configuration(proxyBeanMethods = false)
public class DataSourceInitializerConfiguration {
@Bean
SqlDataSourceScriptDatabaseInitializer sqlDataSourceScriptDatabaseInitializer(GatewayDataSourceContext context) {
SqlInitializationProperties sqlInitializationProperties = new SqlInitializationProperties();
sqlInitializationProperties.setSchemaLocations(Collections.singletonList("classpath:schema.sql"));
sqlInitializationProperties.setDataLocations(Collections.singletonList("classpath:data.sql"));
return new SqlDataSourceScriptDatabaseInitializer(context.getDataSource(), sqlInitializationProperties);
}
}
JDNI 방식으로 데이터베이스를 설정하는 방법은 아래 페이지에서 예시를 확인할 수 있습니다.
다중 데이터베이스를 설정하는 방법은 아래 페이지에서 예시를 확인할 수 있습니다.
리소스 파일 버전을 확인하여 최신 리소스 파일 정보를 조회하는 기능으로, 다운로드 설정이 필요합니다.
msp:
gateway:
resource-update:
use-force-https: true
https-port: 443
download-url:
download-type: filename
Mobile App으로 부터 온 API 요청에 대한 파라미터 및 요청API URL을 기록하는 기능입니다. 기록 시점은 API요청 후 로직 처리가 완료된 후 입니다.
msp:
gateway:
event-log:
path: /Users/uracle/temp/log/msp-gw/eventlogs/
enabled: true
cron: 0 0/30 * * * ?
이벤트 로그 사용 여부가 true일 경우 Spring Boot Scheduler가 동작하여 이벤트 로그 저장 경로(path)에 stat_{yyyyMMdd}.log 형식의 파일이 생성됩니다. 로그 내용은 아래와 같습니다.
0|1.0|TEST_APP|26|Android|111111223333338|SM-N960F|01099999999|/api/res/auto-update||PostmanRuntime/7.36.0|0:0:0:0:0:0:0:1|2024-01-16 10:40:12||||com.uracle.push.demo
각 항목은 다음과 같습니다.
|번호|앱 버전|앱 이름|시스템 버전|시스템 이름|디바이스 아이디|디바이스 모델|전화번호|회사 코드|서비스 코드|사용자 에이전트|호스트|생성 일시|사용자 아이디|사용자 이름|페이지 이름|앱 아이디
구분자(‘|’)를 기준으로 파싱하여 하루 뒤에 Database에 저장됩니다. 읽은 파일은 stat_{yyyyMMdd}.log.stored_yyyyMMddHH24mmss_index
형식으로 변경됩니다.
stat_20240227.log.stored_20240228160100_1
App Store기능을 사용하는 경우, App Store 설정이 필요합니다.
msp:
gateway:
app-store:
service-path: http://127.0.0.1/msp-admin/
bin-path: apk
upload-path: /apps/msp-admin/
file:
upload:
location: /Users/uracle/temp/trash/upload
http:
server:
url: http://localhost:9090
legacy:
url: http://localhost:8080/msp-gw/api/file/download/
download: /Users/uracle/temp/trash/download/
push:
url: http://127.0.0.1:8380