Spring Legacy 설정
JDK , Tomcat, Spring Project 설정
Last updated
JDK , Tomcat, Spring Project 설정
Last updated
- ORACLE 다운로드
- IntelliJ 다운로드
- Win + R 실행창 열기
- cmd 입력 후 엔터
- cmd 창에서 java -version
zip 버전 다운로드 후 압축 풀기
IntelliJ 구성편집에서 구성 추가 후 Tomcat 로컬 선택
Tomcat 인식 못할 경우 압축해제 한 Tomcat 폴더를 구성에서 설정 해주기
콘솔 한글 깨짐 현상 방지를 위해서 VM Option에 아래 코드 추가
-Dfile.encoding=UTF-8
-Dconsole.encoding=UTF-8
포트 수정 필요 시 변경 후 저장
배포 탭에서 아티팩트 선택 후 애플리케이션 컨택스트 수정 후 확인
plugins {
id 'java'
id 'war'
}
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.9.2'
}
sourceCompatibility = '11'
targetCompatibility = '11'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
dependencies {
compileOnly('javax.servlet:javax.servlet-api:4.0.1')
/* Spring*/
implementation group: 'org.springframework', name: 'spring-core', version: '5.3.19'
implementation group: 'org.springframework', name: 'spring-context', version: '5.3.19'
implementation group: 'org.springframework', name: 'spring-test', version: '5.3.19'
implementation group: 'org.springframework', name: 'spring-webmvc', version: '5.3.19'
implementation group: 'org.springframework', name: 'spring-jdbc', version: '5.3.19'
implementation group: 'org.springframework', name: 'spring-tx', version: '5.3.19'
/* DB */
implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '3.0.4'
implementation group: 'com.zaxxer', name: 'HikariCP', version: '5.0.1'
implementation group: 'org.mybatis', name: 'mybatis', version: '3.5.9'
implementation group: 'org.mybatis', name: 'mybatis-spring', version: '2.0.7'
/* Lombok*/
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.24'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.24'
testImplementation 'org.projectlombok:lombok:1.18.28'
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.24'
/* log4j*/
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.2'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.2'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.17.2'
implementation group: 'jstl', name: 'jstl', version: '1.2'
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Encoding 필터 설정-->
<filter>
<filter-name>encoding</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>encoding</filter-name>
<servlet-name>appServlet</servlet-name>
</filter-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">
<context:component-scan base-package="com.example.springex"/>
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="driverClassName" value="org.mariadb.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mariadb://localhost:3306/"/>
<property name="username" value="root"/>
<property name="password" value="bitc5600"/>
<property name="dataSourceProperties">
<props>
<prop key="cachePrepStmts">true</prop>
<prop key="prepStmtCacheSize">250</prop>
<prop key="prepStmtCacheSqlLimit">2048</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:/mapper/**/*.xml"/>
</bean>
<mybatis:scan base-package="com.example.springex.mapper"></mybatis:scan>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!--MVC 설정을 어노테이션 기반으로 처리한다-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--이미지나 정적인 html 파일의 경로를 지정-->
<mvc:resources mapping="/resources/**" location="/resources/"></mvc:resources>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="INFO">
<Appenders>
<!-- 콘솔 -->
<Console name="console" target="SYSTEM_OUT">
<PatternLayout charset="UTF-8" pattern="%d{hh:mm:ss} %5p [%c] %m%n"/>
</Console>
</Appenders>
<loggers>
<logger name="org.springframework" level="INFO" additivity="false">
<appender-ref ref="console" />
</logger>
<logger name="com.example.springex" level="INFO" additivity="false">
<appender-ref ref="console" />
</logger>
<root level="INFO" additivity="false">
<AppenderRef ref="console"/>
</root>
</loggers>
</configuration>
DB는 필요에 따라서 다른 DB 설치해도 무방
현재 프로젝트에서는 mariaDB 기준으로 설명
현재 프로젝트는 mariaDB 10.5 버전 사용
UTF8 옵션 체크
root/ bitc5600 사용
DB 변경 시 jdbc 드라이버 변경 및 DB 정보( root-context.xml) 변경 필요
Spring Legacy Template 뚝딱 완성!