나를 위해 작성 ^-------^
1. pom.xml
org.springframework-version 5.2.3.RELEASE 로 변경
org.aspectj-version 1.9.5 로 변경
org.slf4j-version 1.7.30 로 변경
hibernate
서버 유효성 검사
<!-- hibernate -->
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.2.Final</version>
</dependency>
jackson databind
<!-- Jackson Databind -->
<!-- Java용 json 라이브러리(XML/YAML/CSV) data processing 툴 -->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.1</version>
</dependency>
JDBC
<!-- Spring JDBC Artifacts -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
MyBatis
<!-- Mybaits -->
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.3</version>
</dependency>
Oracle/MySql
(Oracle은 12c 버전)
<!-- Oracle -->
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>21.3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.database.nls/orai18n -->
<dependency>
<groupId>com.oracle.database.nls</groupId>
<artifactId>orai18n</artifactId>
<version>21.3.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
2. web.xml
한국어 사용을 위한 문자 인코딩 방식 변경
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3. root-context.xml
네임스페이스 beans, context, jdbc, mybatis-spring, tx 선택
MyBatis 연동을 위한 bean 등록 및 의존관계 설정
Data source bean
Oracle/Mysql
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<!-- 오라클 사용자 이름 -->
<property name="username" value="MINDI"/>
<!-- 오라클 사용자 비밀번호 -->
<property name="password" value="admin"/>
<property name="validationQuery" value="SELECT 1" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/kko?autoReconnection=true;allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC" />
<property name="username" value="webcompiler" />
<property name="password" value="admin" />
<property name="maxActive" value="5" />
<property name="validationQuery" value="SELECT 1" />
<property name="testWhileIdle" value="true" />
</bean>
MyBatis SqlSessionFactory bean
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- mybatis-config.xml 파일 위치 설정 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- Mapper 파일 위치 설정 -->
<property name="mapperLocations" value="classpath:mappers/Mapper.xml"></property>
</bean>
MyBatis Spring SqlSessionTemplate bean
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>
</bean>
트랜잭션 관리 객체
<!-- 트랜젝션 관리 객체 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
transaction annotation
<!-- @Transactional 어노테이션 처리 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
4. mybatis-config.xml
src/main/resources에 mybatis-config.xml 파일 생성
typeAliase: 매핑 파일에서 지정하는 자바클래스에 대한 별칭을 할당
앞으로 사용할 Mapper 파일에서 parameterType 이나 resultType에 사용하는
클래스 이름에 typeAliases에 등록한 이름을 생략할 수 있다.
<?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>
<typeAliases>
<package name="org.kpu.web.domain" />
</typeAliases>
</configuration>
5. mapper.xml 작성
src/main/resources 에 mappers 폴더 - Mapper.xml 파일 생성
namespace 에는 Mapper.xml 의 경로
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.kpu.web.mapper.Mapper">
</mapper>