Spring에서 오라클 기준으로 데이터베이스를 사용하기 위해선 아래와 같은 라이브러리들이
필요하당. 보통 커넥션풀로 Apache Commons DBCP2를 많이 사용했는뎅, 여기선
요즘 많이 쓰는 Hikari(일본어로 빛이란 뜻) CP를 사용하려 한당!
기본
<properties>
<java-version>1.8</java-version>
<org.springframework-version>5.3.29</org.springframework-version>
<org.aspectj-version>1.9.19</org.aspectj-version>
<org.slf4j-version>2.0.7</org.slf4j-version>
</properties>
pom.xml
<!-- Jackson JSON용 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
<!-- servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
데이타 베이스 사용을 위해 필요한 라이브러리들 (외우려 하지 말공 일단 참공!)
HikariCP # 5.X 버젼부터 jdk11, jdk8은 4.x 버젼
ojdbc8 # 오라클 드라이버
mybatis #
mybatis-spring #
spring-jdbc #
spring-tx # spring-jdbc를 설치하면 compile-dependency로 따라옴
## 참고롱: mybatips 플러그인을 사용하면 꽤나 아주 마니 편하당!
## mybatipse로 껌쌕함당. 요기성
자바 계열에선 단위테스트 라이브러리롱 JUnit을 많이 사용해 왔는뎅.
Junit은 버젼5 부터 근본적으로 전체 구성을 재 설계해서 테스트 프레임워크로 거듭남!
테스트 사용을 위해 필요한 라이브러리
junit-jupiter-engine # junit5 테스트 프레임워크, 요것만 넣으면 요것 조것 자동으로 딸려옴
spring-test
pom.xml
<!-- 기존에 많이 쓰던 commons-dbcp
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
-->
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.3</version>
</dependency>
<!-- ojdbc8 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>23.2.0.0</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.13</version>
</dependency>
<!-- mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.1.1</version>
</dependency>
<!-- spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<!-- spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.29</version>
<scope>test</scope>
</dependency>
database-context.xml
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="driverClassName"
value="oracle.jdbc.OracleDriver"></property>
<property name="jdbcUrl"
value="jdbc:oracle:thin:@localhost:1521:XE"></property>
<property name="username" value="java"></property>
<property name="password" value="oracle"></property>
</bean>
<bean id="datasource" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
<constructor-arg ref="hikariConfig"></constructor-arg>
</bean>
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="configLocation" value="classpath:config/mybatis-config.xml" />
<property name="mapperLocations" value="classpath:mapper/*-Mapper.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
<mybatis-spring:scan base-package="맵퍼있는패키지"/>
</beans>
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"/>
<setting name="jdbcTypeForNull" value="VARCHAR"/>
</settings>
<typeAliases>
</typeAliases>
</configuration>
스프링 테스통
@ExtendWith(SpringExtension.class) // junit5 test framework를 쓰겠다는 이야깅
@ContextConfiguration("classpath:config/spring/database-context.xml")
public class MerongTest {
@Test
public void justTest() {
//Assertions.assertEquals(기대값,실제값);
}
}
곧 가게 해줭
https://www.youtube.com/watch?v=ax39SjW2gTs
초간단 WebSocket 채팅 (16) | 2022.04.28 |
---|---|
MVC이해 (0) | 2022.04.27 |
HttpClient (5) | 2022.04.27 |
SQL로그 출력 (0) | 2022.04.17 |
pom.xml등 설정파일 긁어가깅 (0) | 2022.04.17 |