Spring legacy로 열심히 만든 나의 '호두스케쥴러'를 Spring Boot로 마이그레이션해보았다.

화면과 기능은 모두 동일하다.
다른건 할만했는데 jsp 파일을 thymeleaf로 바꾸는게 정~~말 힘들었다.
jstl, el을 thymeleaf 문법으로 변환하는게 힘들었는데 여러 블로그들의 도움을 많이 받았다. 그 부분은 앞으로의 포스팅에서 남길 예정이다.
우선 설정 부분이다.
spring에서는 maven을 사용했는데 boot에서는 gradle을 이용했다.
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.6'
id 'io.spring.dependency-management' version '1.1.5'
}
group = 'com.multi'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation group: 'org.bgee.log4jdbc-log4j2', name: 'log4jdbc-log4j2-jdbc4.1', version: '1.16'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.3'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
}
tasks.named('test') {
useJUnitPlatform()
}
spring legacy에선 root-context.xml, servlet-context.xml에 설정했었던 내용을 yml파일로 설정했다.
server:
port: 8090
spring:
# DB 연결
datasource:
# url: jdbc:oracle:thin:@localhost:1521/xe
#url: jdbc:oracle:thin:@192.168.0.24:1522/xe
url: jdbc:log4jdbc:mysql://localhost:3306/scott
# 접속을 위한 드라이버
#driver-class-name: oracle.jdbc.OracleDriver
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
username: scott
password: tiger
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML5
cache: false
logging:
level:
sql: trace
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>
<!-- SQL문 정의할 때 VO표현을 간단하게 하고 싶은 경우. 별명을 지어서 사용 -->
<settings>
<setting name="jdbcTypeForNull" value="NULL" />
<!-- DB 조회결과 snake_case -> camelCase 변환 -->
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
<typeAliases>
<typeAlias
type="com.multi.hodooScheduler.user.model.dto.UserDTO"
alias="userDTO"/>
<typeAlias
type="com.multi.hodooScheduler.task.model.dto.TaskDTO"
alias="taskDTO"/>
<typeAlias
type="com.multi.hodooScheduler.diary.model.dto.DiaryDTO"
alias="diaryDTO"/>
<typeAlias
type="com.multi.hodooScheduler.diary.model.dto.PageDTO"
alias="pageDTO"/>
<typeAlias
type="com.multi.hodooScheduler.user.model.dto.AuthDTO"
alias="AuthDTO"/>
</typeAliases>
<mappers>
<!-- SQL문 정의하는 파일들의 목록을 지정. 테이블당 한개 사용 -->
<mapper resource="mappers/userMapper.xml" />
<mapper resource="mappers/taskMapper.xml" />
<mapper resource="mappers/diaryMapper.xml" />
</mappers>
</configuration>
import org.apache.ibatis.annotations.Mapper;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
@Configuration
@EnableTransactionManagement
// @MapperScan(basePackages = {"com.multi.hodooScheduler"} , annotationClass = Mapper.class)
public class MybatisConfig {
@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
//sqlSessionFactory 생성
@Bean
public SqlSessionFactory sqlSessoinFactory(DataSource datasource) throws Exception{
SqlSessionFactoryBean seb = new SqlSessionFactoryBean();
seb.setDataSource(datasource);
seb.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
return seb.getObject();
}
@Bean
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory){
return new SqlSessionTemplate(sqlSessionFactory);
}
}
본 포스팅은 멀티캠퍼스의 멀티잇 백엔드 개발(Java)의 교육을 수강하고 작성되었습니다.