---
description: JDK , Tomcat, Spring Project 설정
---

# Spring Legacy 설정

## \[1] JDK 설정

### 1.JDK 다운로드&#x20;

&#x20;**-  ORACLE 다운로드**&#x20;

{% embed url="https://www.oracle.com/kr/java/technologies/javase/jdk11-archive-downloads.html" %}
JDK 11 Version
{% endembed %}

{% embed url="https://www.oracle.com/kr/java/technologies/downloads/#java17" %}
JDK 17 Version
{% endembed %}



&#x20; **-  IntelliJ 다운로드**&#x20;

<div><figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2F0vIGZG5ePr8ncxJA2mED%2FScreenshot_14.png?alt=media&#x26;token=48d1ed69-11ad-409d-bbf0-64f20bc8658a" alt=""><figcaption></figcaption></figure> <figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2F5hKPemVIpxrTfzcO9nfl%2FScreenshot_15.png?alt=media&#x26;token=928d9995-3de3-4940-9c1d-4d845db63964" alt=""><figcaption></figcaption></figure></div>



### 2. 환경변수 설정

<div><figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2F6j2PP6xAtTBy3Vyzvie3%2FScreenshot_16.png?alt=media&#x26;token=46b13592-c2ea-4992-876e-4f7ec6cab394" alt=""><figcaption></figcaption></figure> <figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2FtTifQ72o9UcZEASTpYjb%2FScreenshot_17.png?alt=media&#x26;token=116abfc4-d33d-4d80-932d-b7ec34a2cc25" alt=""><figcaption></figcaption></figure></div>

### 3. 설정 확인

&#x20; \- Win + R 실행창 열기&#x20;

&#x20; \- cmd 입력 후 엔터

&#x20; \- cmd 창에서 java -version&#x20;

<figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2FB4uSKYfgWNBwjCmvK61T%2FScreenshot_18.png?alt=media&#x26;token=cecf93e3-7b88-4049-9372-979521bf1718" alt=""><figcaption></figcaption></figure>

## \[2]. Project 생성&#x20;

<div><figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2F1CQ3BCqg8p4TACOjjUiK%2FScreenshot_19.png?alt=media&#x26;token=6b7535a5-53a8-421f-aa49-9f5c6676392d" alt=""><figcaption></figcaption></figure> <figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2FkH0wv1tdklv1k1KE1gt0%2FScreenshot_20.png?alt=media&#x26;token=fc659319-e574-49ad-9832-e73a7b9006cd" alt=""><figcaption></figcaption></figure></div>

## \[3]. Tomcat 설정&#x20;

{% embed url="https://tomcat.apache.org/download-90.cgi" %}
tomcat 9 Version
{% endembed %}

zip 버전 다운로드 후 압축 풀기&#x20;

IntelliJ 구성편집에서 구성 추가  후 Tomcat 로컬 선택&#x20;

Tomcat 인식 못할 경우 압축해제 한 Tomcat 폴더를 구성에서 설정 해주기

콘솔 한글 깨짐 현상 방지를 위해서 VM Option에 아래 코드 추가&#x20;

`-Dfile.encoding=UTF-8`

`-Dconsole.encoding=UTF-8`

포트 수정 필요 시 변경 후 저장&#x20;

배포 탭에서 아티팩트 선택 후 애플리케이션 컨택스트 수정 후 확인

<div><figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2F0K8wJZ4WAZPaNeoDOAPd%2FScreenshot_21.png?alt=media&#x26;token=7c25a5f9-433b-4cd0-a884-0b9d4a85b9a3" alt=""><figcaption></figcaption></figure> <figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2FDMLVl2ReoWm8d74xCL1B%2FScreenshot_22.png?alt=media&#x26;token=136ed28a-9ea3-4e44-9408-84fd37344f6e" alt=""><figcaption></figcaption></figure> <figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2FersGQ182dH6nyZeYsrdI%2FScreenshot_23.png?alt=media&#x26;token=cb21c28a-284f-4b58-a2ee-bb8edd853ec9" alt=""><figcaption></figcaption></figure> <figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2F9CBEJez1hQSdv5xvZqU7%2FScreenshot_24.png?alt=media&#x26;token=c832a2db-80fa-4b47-8e8f-a110664f4efa" alt=""><figcaption></figcaption></figure></div>



## \[4]. Spring 설정&#x20;



### 1. build.gradle 설정

```gradle
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()
}
```

### 2. web.xml 설정



```xml
<?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>
```



### 3. root-context.xml

```xml
<?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>
```





### 4. servlet-context.xml

```xml
<?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>
```



### 5. log4j2.xml&#x20;

{% code title="main/resources/log4j2.xml" %}
```xml
<?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>

```
{% endcode %}



## \[5]. DB 설치

### 1. DB 다운로드

&#x20;DB는 필요에 따라서 다른 DB 설치해도 무방

&#x20;현재 프로젝트에서는 mariaDB 기준으로 설명



{% embed url="https://mariadb.org/download/?t=mariadb&p=mariadb&r=11.4.0" %}
maria DB Download
{% endembed %}

현재 프로젝트는 mariaDB 10.5 버전 사용



<figure><img src="https://3814826491-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJyHOwztPxBT3bLpisjCt%2Fuploads%2FfpXtgNVjmFBwZuM6Drcm%2FScreenshot_13.png?alt=media&#x26;token=6622d13f-4114-433a-88e1-d5814b33c0f9" alt=""><figcaption></figcaption></figure>



UTF8 옵션 체크

root/ bitc5600 사용

DB 변경 시 jdbc 드라이버 변경 및 DB 정보( root-context.xml) 변경 필요



&#x20;

Spring Legacy Template 뚝딱 완성!
