Document Page
1. ๊ฐ์
1. ํ์์ฑ
ํจ์๋, ๊ธฐํ ์ ๋ฆฌ๊ฐ ํ์ํ ๋ถ๋ถ์ด ์๊ฒผ์ ๋, ๋ณดํต ๋ฌธ์๋ ์คํ๋ ๋ ์ํธ์ ์ ์ฅํ๋ ๊ฒ์ด ๋ณดํต์ด์๋๋ฐ ์ด๋ ๋ค ๋ณด๋ ์ฒด๊ณ์ ์ผ๋ก ์ ๋ฆฌ๊ฐ ๋์ง ์์ ๋ฟ๋๋ฌ, ์ฐพ๊ธฐ๊ฐ ํ๋ค๊ณ ํ์์ ์ด๋ค ๋ด์ฉ์ด ๋ด๊ฒจ์ ธ ์๋์ง ํ์ธ์ด ๋ถ๊ฐ๋ฅ ํ์๋ค. ๊ฐ์ธ์ ์ธ ์ฉ๋๋ ํน์ ์ฌ๋ด์ ๊ณต์ ํ๊ธฐ ์ํ API Developer Document ์ฒ๋ผ ์ ๋ฆฌํ ์ ์๋ ์๋น์ค๊ฐ ์์ผ๋ฉด ์ข๊ฒ ๋ค๊ณ ์๊ฐํ์๋ค.
2. ๋ชฉ์
๋ชฉ์ ์ ํ์์ฑ๊ณผ ๊ฐ์ ๋งฅ๋ฝ์ผ๋ก, ์ ๋ฆฌ๊ฐ ํ์ํ ํจ์๋ ๊ธฐํ ํด๋์ค ๋ฑ์ ์ ๋ฆฌํ์ฌ ๋น ๋ฅด๊ฒ ๋ด๋ถ ์ธ์์๊ฒ ๊ณต์ ํ๊ฑฐ๋ ์ธ๋ถ ์ธ์์๊ฒ ๊ณต์ ๊ฐ ๊ฐ๋ฅํ๋๋ก ํ๋ก์ ํธ ๋ณ ํน์ ํ๋ ์์ํฌ ๋ณ๋ก ์ ๋ฆฌ๋ ๋ฌธ์๋ฅผ ์์ฑ ๋ฐ ๊ณต์ ํ๊ธฐ ์ํจ์ด๋ค.
3. ์ฌ์ฉ ๊ธฐ์ ์คํ
Front : HTML & Vue.js
Back : Spring Boot Framework + Gradle
DB : RDB ( MYSQL / ORACLE ) or etc.
4. ์๋น์ค ๊ตฌ์กฐ (์ด์)
Spring Boot Framework ๊ตฌ์ฑ ์, ํธ๋์ญ์ ๊ณผ ์คํ๋ง ์ํ๋ฆฌํฐ ์ ๋๋ ํฌํจํ์ฌ ๊ตฌ์ฑํ๋ ค๊ณ ์๊ฐ ์ค์ด๋ค.
๋ํ ๋ก๊ทธ ์ฒ๋ฆฌ ๊ฐ์ ๊ธฐ๋ณธ์ ์ธ ๋ถ๋ถ๋ Boot Project ๋ ์ฒ์์ด๋ผ ๊ณต๋ถํ๋ฉด์ ์งํํ ์์ ์ด๋ค.
๊ทธ ์ธ์ ์ถ๊ฐ์ ์ผ๋ก ์๋น์ค๋ฅผ SPA ๋ฐฉ์์ผ๋ก ๊ตฌ์ฑ์ ํ ๊น ์๊ฐ ์ค์ธ๋ฐ, ์ ์ฉ์ ํ ์ ์์ ์ง ์๋ฌธ์ด๋ค.
์ ๊ฐ๋ ์ ๊ฐ์ง๊ณ ์ ๊ทผํด๋ณผ ์๊ฐ์ด๋ฉฐ, ํ๋ฉด์ค๊ณ ๋ถํฐ ์ฐจ๊ทผ์ฐจ๊ทผ ์งํํด๋ณผ ์์ ์ด๋ค.
2. ๊ฐ๋จํ ํ๋ฉด ์ค๊ณ
๊ฐ๋จํ๊ฒ ์๊ฐ๋ฌ๋ ์์ด๋์ด ๋ฐ ํ๋ฉด ๋ด์ฉ์ ๊ฐ๋จํ๊ฒ ํ์ํฌ์ธํธ๋ก ์ค๊ณํด๋ณด์๋ค.
์ถํ ์งํ ๋๋ ํ๋ฒ ๋ ๋ณด๋ฉด์ ์์ ํด ๋๊ฐ ์์ ์ด๋ค.
3. Spring Boot ๊ธฐ๋ฐ ํ๋ก์ ํธ ์งํ
ํ๋ก์ ํธ์ DB๋ฅผ ์ฐ๋ํด์ผ ํด์, ๊ณ ๋ฏผ์ ํด๋ณธ ๊ฒฐ๊ณผ ...
์ ์ฅ๋ ๋ฐ์ดํฐ๊ฐ ๋ง์ง ์๊ณ , ํ ์ด๋ธ๋ ๋ง์ด ํ์ํ๊ฒ ์๋๋ผ์ No SQL ์ชฝ์ ์์๋ณด์๋๋ฐ ์ฌ์ค์ ์๊ธ๋ฌธ์ ๊ฐ ์์ด์ ์ด๋์ ๋ ํ ์คํธ์ ๊ฐ๋จํ ๊ตฌํ ๋๋์ผ๋ก ์งํํ๋๋ฐ์๋ ์ ํฉํ์ง ์์ ๊ฒ ๊ฐ์ RDB๋ฅผ ๊ทธ๋ฅ ์ฐ๋ํ๊ธฐ๋ก ํ์๋ค.
DB๋ ORACLE ์ด๋ฉฐ, ์ฐ์ ORACLE ๋ก ์ฐ๊ฒฐ ๋๋ ๋ถ๋ถ์ ํ์ธ ํ์, MYSQL ๊น์ง ์ฐ๋ ๊ฐ๋ฅํ๊ฒ ์์ ํ ์์ ์ด๋ค.
์ฐ์ , ํ๋ก์ ํธ ํ๊ฒฝ์ ๋ค์๊ณผ ๊ฐ๋ค.
- JDK11
- Spring Boot
๊ธฐ๋ณธ์ ์ผ๋ก vscode extension ์์ ์์ฑํ๋ ๋ถํธ ํ๋ก์ ํธ๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉํ์๋ค.
DB ํ๊ฒฝ์ HikariCP๋ฅผ ์ด์ฉํ์ฌ Oracle ๊ณผ Connection ์ ๋งบ๊ณ , log4j ๋ฅผ ํตํด DB ๋ก๊ทธ๋ฅผ ์ถ๋ ฅํ๋ ๊ฒ์ผ๋ก ํ์๋ค. ๊ทธ๋ฆฌ๊ณ , DB mapper ์ฐ๋์ MyBatis ๋ฅผ ํตํด ์งํํ๋ค.
1. ํ์ Dependency ์ถ๊ฐ.
// https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter
implementation group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '2.1.4'
// log4j2
implementation group: 'org.bgee.log4jdbc-log4j2', name: 'log4jdbc-log4j2-jdbc4.1', version: '1.16'
// https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8
implementation group: 'com.oracle.database.jdbc', name: 'ojdbc8', version: '21.1.0.0'
DB ์ปค๋ฅ์ ์ ์ํด์๋ ojdbc ๋ํ ํ์ํ๋ค. ๋ฒ์ ๋ง๋ค ์ง์ํ๋ JDK ๋ฒ์ ์ด ๋ค๋ฅด๋ ํ์ธ์ด ํ์ํ๋ค.
2. application.yml ์์ฑ
๋ณดํต ํ๋ก์ ํธ ์์ฑ ํ์๋ application.properties ๋ก ๋์ด์์ง๋ง, ํธ์๋ฅผ ์ํด yml ํ์ผ๋ก ๋ฐ๊พธ์๋ค. ๊ทธ๋๋ก properties ๋ก ์งํํด๋ ์๊ด ์์ผ๋, ํ๊ธฐ๋ฒ์ด ๋ค๋ฅด๋ค.
# /resource/application.yml
spring:
application:
name: springboot-project-name
# DB Connection
datasource:
hikari:
jdbc-url: jdbc:log4jdbc:oracle:thin:@{oracle-db-url} # ex ) localhost:3306:utf8
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
username: {user-name}
password: {user-password}
maximum-pool-size: {connection-pool-size}
DB์ฐ๊ฒฐ ์ ๋ณด๋ฅผ ์์ฑํ๋ค.
3. log4j properties ์์ฑ
log4j ํ๋กํผํฐ๋ฅผ ์์ฑํ๋ค. ์์ธํ ๊ฑด ๋ชจ๋ฅด๊ฒ ์ผ๋, ๋ณดํต ์ด๋ ๊ฒ ์ธํ ํ๊ณ ์จ์ ๊ทธ๋๋ก ๊ฐ์ ธ์๋ค.
# /resource/log4j. log4jdbc.log4j2.properties.yml
log4jdbc.spylogdelegator.name = net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength = 0
#Disable - Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
log4jdbc.auto.load.popular.drivers = false
4. logback ์์ฑ
๋ก๊ทธ๋ฅผ ์ด๋ค ํ์์ผ๋ก ์ด๋ป๊ฒ ์ถ๋ ฅํ ๊ฒ์ด๋ฉฐ, ๋ก๊ทธ ๋ ๋ฒจ์ ์ง์ ํ๋ค.
# /resource/logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm} %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<appender name="SAMPLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="{project-package-dir}" level="DEBUG" additivity="false">
<appender-ref ref="SAMPLE" />
</logger>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
<logger name="jdbc" level="OFF" />
<logger name="jdbc.sqlonly" level="OFF" />
<logger name="jdbc.sqltiming" level="DEBUG" />
<logger name="jdbc.audit" level="OFF" />
<logger name="jdbc.resultset" level="OFF" />
<logger name="jdbc.resultsettable" level="DEBUG" />
<logger name="jdbc.connection" level="OFF" />
</configuration>
5. mybatis config ์์ฑ
Mybatis ์ค์ ์ ์์ฑํ๋ค. ํ์ํ ์ต์ ๋ง ๊ฒ์ํ์ฌ ์์ฑํ์๋ค.
# /resource/mybatis/mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true" />
<!-- column์ด NULL ์ผ ๊ฒฝ์ฐ์๋ ์ถ๋ ฅ -->
<setting name="callSettersOnNulls" value="true" />
<!-- row๊ฐ NULL ์ผ ๊ฒฝ์ฐ์๋ ์ถ๋ ฅ -->
<setting name="returnInstanceForEmptyRow" value="true" />
</settings>
</configuration>
6. DB config java ํ์ผ ์์ฑ
์ค์ ๋ก ์ปค๋ฅ์ ์, ์ฌ์ฉํ DataSource ์ Sql Session Template ์ ์ฌ์ฉํ๋๋ก ์์ฑํ๋ค.
mapper ์ ์ค์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ์ฌ ๋ถ๋ฌ์ค๊ณ ์ฐพ์ ์ ์๋๋ก ํ๋ค.
# {package-dir}/config/DBconfig.java
import javax.sql.DataSource;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
@Configuration
@MapperScan(basePackages = "{repositoey-dir}")
public class DatabaseConfig {
@Bean
@ConfigurationProperties("spring.datasource.hikari")
public DataSource dataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sessionFactory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
Resource myBatisConfig = new PathMatchingResourcePatternResolver()
.getResource("classpath:mybatis/mybatis-config.xml");
sessionFactory.setConfigLocation(myBatisConfig);
return sessionFactory.getObject();
}
@Bean
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) throws Exception {
final SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
return sqlSessionTemplate;
}
}
์ฌ๊ธฐ๊น์ง ์์ฑํ๊ณ , ๊ฐ Service ์ Repository ๋ฅผ ์์ฑํ์ฌ ์คํํ๋ฉด ๋ฐ๋ก ํ ์คํธ ๋ฐ ์คํ์ด ๊ฐ๋ฅํ๋ค.
๊ฐ ๋ด์ฉ๋ค์ ๊นํ์ ์ ๋ฆฌํ์ฌ ์ฌ๋ ค๋์๋ค.
๋ฌด์ธ๊ฐ ๋ฐ๋ก๋ฐ๋ก ํ๋ก์ ํธ๋ฅผ ์์ฑํ์ฌ ์งํํ๊ณ ์ถ์ ๋, ์ด๋ฐ ํต ์คํํ ์ด ๊ฐ๋ฅํ ์ฑ๋ก ์ธํ ์ด ๋์ด์์ผ๋ฉด ์ข๊ฒ ๋ค๊ณ ์๊ฐํด์ ์ด๋ฐ ๋ด์ฉ๋ค์ ์ ๋ฆฌํ ๋๋ง๋ค ๊นํ์ ์ฌ๋ ค๋๊ณ ์ฐ๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค.
GitHub - Chiptune93/Library: My Java Util Class
My Java Util Class. Contribute to Chiptune93/Library development by creating an account on GitHub.
github.com
4. ํ๋ก์ ํธ ์์ฑ ๋ฐ ์ด์ํ๊ฒฝ ๊ฒฐ์
ํ๋ก์ ํธ ๊ธฐ๋ฅ ๊ตฌ์ฑ์ ๋๋ด๊ณ , ํผ๋ธ ์์ ์ ๋ถํํ๋ค. ์๊ฐ๋ณด๋ค ์ฌํํ๊ฒ ๋์์ ํ๋ฉด ์ค๊ณ ๋งํผ ๋ณต์กํ๊ฒ ๊ตฌ์ฑํ์ง ์์๋ ๋์๊ณ
๋ก๊ทธ์ธ ๊ฐ์ ๊ธฐ๋ฅ๋ ๋นผ๊ณ ๋์ ๊ด๋ฆฌ ๊ธฐ๋ฅ์ ๋ณํ์ ํค๋ณด๋ ์ ๋ ฅ์ ํตํด ํ๊ธฐ๋ก ํ๋ค.
์ด๋ฐ ์์ผ๋ก ํ์ด์ง๋ ์์ฑ์ด ๋์๊ณ , ์ด๋ฅผ ์ด์ ์ด๋ป๊ฒ ์ด์ํ ๊ฒ์ธ๊ฐ์ ๋ํ ๋ฌธ์ ๊ฐ ๋จ์์๋ค.
์ต๊ทผ, ํ๋ก์ ํธ ํ๋๋ฅผ ์งํํ๋ฉด์ Docker๋ฅผ Study ํ๊ธฐ๋ ํ๊ณ , ํ์ฌ ๋ด๋ถ์์๋ ์ด๋ฅผ ์ํ ์๋ฒ๋ฅผ ํ๋ ๋ง๋ จํ ์ํ์๋ค. ๋ฐ๋ผ์, ๋๋ ์ด ํ๋ก์ ํธ๋ฅผ Docker ์ด๋ฏธ์งํ ํ์ฌ Docker ์๋ฒ์ ์ฌ๋ ค ์ด์ํ๊ธฐ๋ก ํ๋ค. ๊ทธ๋ฆฌ๊ณ DB ๋ํ ์ต๊ทผ ์งํํ ํ๋ก์ ํธ์์ ์ฌ์ฉํ Postgresql ์ ์ฌ์ฉํ๊ธฐ๋ก ํ๊ณ ์ด๊ฒ ๋ํ, ์๋ฒ์ ์ฌ๋ ค๋๊ณ ์ฌ์ฉํ๊ธฐ๋ก ํ๋ค.
๊ฐ๋จํ๊ฒ ์๋ฒ์์ ์์ ํ ๋ด์ฉ์ ๋ค์๊ณผ ๊ฐ์๋ค.
1. Docker & Docker Compose ์ค์น.
2. Docker Image pull ๋ฐ๊ธฐ > Postgresql, ๋ง๋ ํ๋ก์ ํธ์ image
3. Docker run์ผ๋ก run ์ํค๊ธฐ.
- Dockerfile
FROM adoptopenjdk/openjdk11
EXPOSE 8080:8080
ARG WAR_FILE=build/libs/api.war
COPY ${WAR_FILE} api.war
ENTRYPOINT [ "java", "-jar", "/api.war" ]
๋จ์ํ๊ฒ war๋ก ๋ง๋ฆฐ ์ด๋ฏธ์ง๋ฅผ run ํ๋ ๊ฒ์ด๋ค.
- ์ฌ์ฉํ Command
1. build
docker build -t api:1.0 .
2. docker run
docker run -d -p 8080:8080 --name syworks-api api:1.0
3. docker push
docker push api:1.0
์ด๋ก์จ ๋ญ๊ฐ ๋น ๋ฅด๊ฒ ๋น ๋ฅด๊ฒ ์ฒซ Spring Boot + Vuejs ํ๋ก์ ํธ๋ Docker๊ธฐ๋ฐ์ผ๋ก ์ด์ํ๊ธฐ๋ก ํ๋ ๋ฐ๋์ ์๊ฐ๋ณด๋ค ๊ธ๋ฐฉ ๋๋๊ฒ ๋์๋ค.
์ถ๊ฐ์ ์ผ๋ก, ์ด๋ฒ ํ๋ก์ ํธ๋ฅผ ์ด์์ ์ฌ๋ฆฌ๋ฉด์ nginx๋ฅผ ์ฌ๋ ค์ ์ฌ๋ฌ๊ฐ ํ๋ก์ ํธ๋ฅผ ์ด์ํ ์ ์๊ฒ ํ๋ ๊ฒ์ ๋ด๋ถ์์ ์ ์ํ์ ์ ๊ทธ๊ฒ๋ ๊ณ ๋ คํด๋ณด๊ฒ ๋์๋ค. ์๋ง ๋ค์๋ฒ ๊ฐ์ธ ํ๋ก์ ํธ๋ฅผ ์งํํ๊ฒ ๋๋ค๋ฉด ๊ณ ๋ คํด๋ณด์์ผ ๊ฒ ๋ค.
5. ์๋ฃ ๋ฐ ๊ณต์
https://github.com/Chiptune93/DocumentsPage
GitHub - Chiptune93/DocumentsPage
Contribute to Chiptune93/DocumentsPage development by creating an account on GitHub.
github.com
ํด๋น ํ๋ก์ ํธ๋ ๊ฐ๋ฐ ์ข ๋ฃ ํ๊ณ , ๋ค์ ํ๋ก์ ํธ๋ฅผ ๊ตฌ์ํด๋ณด๊ฒ ์ต๋๋ค :D