ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Intellij ์—์„œ Spring MVC + Gradle ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
    PROGRAMMING/Spring 2022. 10. 26. 16:11

     

    Spring Boot ๋งŒ ์‚ฌ์šฉํ•˜๋‹ค, Spring MVC ๊ตฌ์กฐ๋ฅผ ๋” ํŒŒ์•…ํ•˜๊ณ ์ž Spring MVC ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ด์„œ ๊ฐœ๋ฐœํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

     

    Spring Boot ๋Š” Spring MVC ๋ฅผ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •๋“ค์„ ์ž๋™์œผ๋กœ ๊ตฌ์„ฑํ•ด์ฃผ์–ด ๊ฐœ๋ฐœ์ž๋“ค์˜ ํŽธ์˜๋ฅผ ๋†’์—ฌ์ฃผ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์ž…๋‹ˆ๋‹ค. ์ฒ˜์Œ์— Spring ์ด๋ผ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ ‘ํ•˜๊ธฐ์—” ์ข‹์ง€๋งŒ, ๋‚ด๋ถ€ ๊ตฌ์กฐ๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ง์ ‘ Spring MVC ๋ฅผ ๊ตฌ์„ฑํ•ด๋ณด๋Š” ๊ฒƒ์ด ๋„์›€์ด ๋  ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

     

     

    ์ €์˜ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    ๊ฐœ๋ฐœ ํ™˜๊ฒฝ

    • Windows 10
    • java 12
    • tomcat 9
    • IDE: intellij IDEA ultimate

     

     

    ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ๋ถ€ํ„ฐ Spring MVC ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ• ํ›„,

    ๊ฐ„๋‹จํ•œ Controller ๋ฅผ ์ž‘์„ฑํ•ด ์›นํŽ˜์ด์ง€๋ฅผ ๋„์›Œ๋ณด๋Š” ๊ฒƒ๊นŒ์ง€ ์ง„ํ–‰ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

     

    1) Gradle - Java ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

    Intellij ๋ฅผ ์—ด๊ณ  ์ƒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    Gradle - Java ์™€ Web ์„ ์„ ํƒ ํ›„, ์›ํ•˜๋Š” JDK ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

     

    Gradle-Java

     

    ์ดˆ๊ธฐ ์ƒ์„ฑ ์‹œ, ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

     

    ํ”„๋กœ์ ํŠธ ์ดˆ๊ธฐ ๊ตฌ์กฐ

     

     

    2) Spring MVC ์ถ”๊ฐ€

    ๋จผ์ € ํ”„๋กœ์ ํŠธ ์ด๋ฆ„-์šฐํด๋ฆญ ์‹œ ๋‚˜์˜ค๋Š” Add Framework Support ๋ฅผ ๋ˆŒ๋Ÿฌ์„œ Spring MVC ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

     

    Add Framework Support

     

    spring mvc ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋ฉด ๋‚˜์˜ค๋ฉด ํ•ด๋‹น framework ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.

    Spring, Spring MVC ๋ฅผ ์„ ํƒํ•œ ์ƒํƒœ์—์„œ OK ๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

     

    Spring MVC ์ถ”๊ฐ€

     

    ๊ทธ๋ฆฌ๊ณ  gradle ์—๋„ spring-context, spring-webmvc, spring-test ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

    (์œ„์—์„œ ์ถ”๊ฐ€ํ•œ ๋ฒ„์ „๊ณผ ๋™์ผํ•˜๊ฒŒ)

     

     

    ๊ทธ๋Ÿฌ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด applicationContext.xml, dispatcher-servlet.xml, web.xml ํŒŒ์ผ์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

     

    ์ถ”๊ฐ€๋œ ํŒŒ์ผ๋“ค

     

    Intellij ๊ธฐ์ค€์œผ๋กœ,

    • applicationContext.xml: Bean ์„ค์ •
    • dispatcher-servlet.xml: ๋‚ด๋ถ€ ์›น ๊ด€๋ จ ์ฒ˜๋ฆฌ ์„ค์ •
    • web.xml: Tomcat ๊ตฌ๋™ ๊ด€๋ จ ์„ค์ •

    ์ž…๋‹ˆ๋‹ค.

     

     

     

    3) ํด๋” ๊ตฌ์กฐ ๋ณ€๊ฒฝ

    ํ˜„์žฌ ํด๋” ๊ตฌ์กฐ๋Š” src/main/java ์™€ web/WEB-INF ๊ฐ€ ๋ถ„๋ฆฌ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

    Intellij ๊ฐ€ Gradle ๋นŒ๋“œ ๊ธฐ์ค€์ด ์•„๋‹Œ, ๊ธฐ๋ณธ Java ๋นŒ๋“œ ๊ธฐ์ค€์œผ๋กœ ํด๋” ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

    ํ•˜์ง€๋งŒ, Gradle ๋ฅผ ๋นŒ๋“œ ํˆด๋กœ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋ฏ€๋กœ ์ด๋Ÿฐ ํด๋” ๊ตฌ์กฐ๋กœ๋Š” ์„ค์ • ํŒŒ์ผ๊ณผ ํ•จ๊ป˜ ์ •์ƒ์ ์œผ๋กœ ๋นŒ๋“œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

    (์—ฌ๊ธฐ์—์„œ ๊ณ„์† ์˜ค๋ฅ˜๊ฐ€ ๋–ด์—ˆ๋Š”๋ฐ, ํด๋” ๊ตฌ์กฐ์™€ ์„ค์ • ํŒŒ์ผ์„ ์ž˜ ์œ„์น˜์‹œ์ผœ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค!)

     

    ๋”ฐ๋ผ์„œ, webapp (์ดˆ๊ธฐ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ์‹œ web ์„ ์„ ํƒํ•œ ๊ฒฝ์šฐ์— ์ƒ๊ธฐ๋Š”) ํด๋”์— WEB-INF ๋ฅผ ํ†ต์งธ๋กœ ์˜ฎ๊ฒจ์ค๋‹ˆ๋‹ค.

     

    webapp ์œผ๋กœ ์˜ฎ๊ธฐ๊ธฐ

     

    ๊ทธ ํ›„ ์„ค์ • ํŒŒ์ผ๋“ค์„ context ๋กœ ๋“ฑ๋กํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

     

     

     

    4) ํ”„๋กœ์ ํŠธ ์„ค์ • (Artifacts, Facets)

    ์ด์ œ File->Project Structure ๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.

     

    Project Structure

     

    Artifacts ์— ๋“ค์–ด๊ฐ€๋ฉด, ์šฐ์ธก์— ๊ฐ€๋Šฅํ•œ ์š”์†Œ๋“ค์ด ์œ„์น˜ํ•ด ์žˆ์Šต๋‹ˆ๋‹ค.

    ๊ทธ ์ค‘์—์„œ Spring-5.2.3.RELEASE ๋ฅผ ๋‘ ๋ฒˆ ๋ˆŒ๋Ÿฌ์„œ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

    (gradle ๋นŒ๋“œ ์ „์—๋Š” Spring-MVC-5.2.3.RELEASE ๋„ ๋–ณ๋Š”๋ฐ ๋นŒ๋“œ ํ›„ ์—†์–ด์กŒ์Šต๋‹ˆ๋‹ค)

     

    Artifacts ์ถ”๊ฐ€

     

    ๊ทธ๋ฆฌ๊ณ  Facets ๋ฅผ ์„ค์ •ํ•ด์ค๋‹ˆ๋‹ค.

    ์„ค์ • ํŒŒ์ผ์„ ํ”„๋กœ์ ํŠธ์—์„œ ์ธ์‹ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

    Web Gradle: spring-mvc~ ๋ฅผ ๋ˆŒ๋Ÿฌ์„œ Deployment Descriptors ์— web.xml ์„ ์ถ”๊ฐ€ํ•ด์ค„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

    web.xml ์ถ”๊ฐ€

     

    webapp/WEB-INF/web.xml ์„ ๋“ฑ๋กํ•ด์„œ, Tomcat ๊ตฌ๋™ ๊ด€๋ จ ์„ค์ •์„ ํ”„๋กœ์ ํŠธ์—์„œ ์ธ์‹ํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    ๊ทธ๋Ÿฌ๋‹ˆ web.xml ์˜ ๊ฒฝ๋กœ๋ฅผ ์ž˜ ๋ณด๊ณ  ๋“ฑ๋กํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. (์•„๋งˆ ์ž๋™์œผ๋กœ ๊ฒฝ๋กœ๊ฐ€ ์ž˜ ์ง€์ •๋˜์—ˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.)

     

    ๊ฒฝ๋กœ ํ™•์ธ

     

    ์•„๋ž˜์™€ ๊ฐ™์ด ๋‚˜์˜ค๋ฉด ์ž˜ ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค! (autodetected!)

     

     

    ์ด๋ ‡๊ฒŒ ํด๋” ๊ตฌ์กฐ๋ฅผ ๋ฐ”๊พธ๊ณ  web.xml ์„ ๋“ฑ๋กํ•ด์ฃผ๋ฉด,

    ๊ธฐ์กด์— ์•„๋ž˜์™€ ๊ฐ™์ด ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋˜ web.xml ์—์„œ springframework ๋ฅผ ์ž˜ ์ธ์‹ํ•ด์„œ ๋นจ๊ฐ„์ค„์ด ์—†์–ด์ง‘๋‹ˆ๋‹ค!

     

     

    (์•„๋ฌด๋ฆฌ ํ•ด๋„ ์ € spring framework ๋ฅผ ์ธ์‹ํ•˜์งˆ ๋ชปํ•ด์„œ web.xml ์ž์ฒด๋ฅผ ์ธ์‹ํ•˜์ง€ ๋ชปํ•œ ๊ฒŒ ์•„๋‹Œ๊ฐ€ ํ•˜๊ณ  ์ฐพ์•„๋ณด๋‹ˆ intellij ๊ฐ€ ๊ตฌ์„ฑํ•ด์ฃผ๋Š” ํด๋” ๊ตฌ์กฐ์™€ ํ”„๋กœ์ ํŠธ์˜ ๊ตฌ์„ฑ์˜ ๋ถˆ์ผ์น˜ ๋•Œ๋ฌธ์ด์—ˆ์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž)

    (facets ๊ด€๋ จ ์ฐธ๊ณ : https://www.jetbrains.com/help/idea/adding-support-for-frameworks-and-technologies.html)

     

    Add frameworks (facets) | IntelliJ IDEA

     

    www.jetbrains.com

     

     

     

    5) ์„ค์ • ํŒŒ์ผ(.xml) ์ˆ˜์ •

    ์ด์ œ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ์™€ ํ•„์š”ํ•œ ๋ชจ๋“ˆ๋“ค์„ ๋‹ค ๋“ฑ๋กํ–ˆ์œผ๋ฏ€๋กœ, Spring ์„ค์ •์„ ํ•ด์ค๋‹ˆ๋‹ค.

    ํ•„์ˆ˜์ ์ด์ง„ ์•Š๊ณ  ํ”„๋กœ์ ํŠธ ์š”๊ตฌ์‚ฌํ•ญ์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๊ฒƒ์ด '์„ค์ • ํŒŒ์ผ'์ด๋ฏ€๋กœ, ์ž์‹ ์—๊ฒŒ ๋งž๋Š” ์˜ต์…˜์„ ์„ ํƒํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

     

    ๊ทธ๋Ÿผ ์ผ๋ฐ˜์ ์œผ๋กœ ๋งŽ์ด ํ•˜๋Š” ์„ค์ •์— ๋Œ€ํ•ด ๋‹ค๋ค„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

    web.xml ์˜ ๊ฒฝ์šฐ Intellij ultimate ์ด๋ฉด ์ž๋™์œผ๋กœ ์ž‘์„ฑํ•ด์ค๋‹ˆ๋‹ค.

    ๋‹ค๋งŒ, ํ•œ ๊ฐ€์ง€ ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

    • ๋งจ ์•„๋ž˜ servlet-mapping ์˜ url-pattern ์„ / ๋กœ ๋ฐ”๊ฟ”์ค๋‹ˆ๋‹ค. (URL์„ / ๊ธฐ๋ฐ˜์œผ๋กœ ์ธ์‹ํ•  ๊ฒƒ์ด๋ฏ€๋กœ)
    <?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/applicationContext.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    </web-app>

     

     

    applicationContext.xml ์€ ์•„์ง ์ˆ˜์ •ํ•  ์‚ฌํ•ญ์ด ์—†์–ด์„œ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค.

     

     

    dispatcherServlet.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:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context.xsd
           http://www.springframework.org/schema/mvc
           http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
        <!-- Annotation ํ™œ์„ฑํ™” -->
        <mvc:annotation-driven/>
        <!-- Component ํŒจํ‚ค์ง€ ์ง€์ • -->
        <context:component-scan base-package="com.simple"/>
    
        <!-- view object ์ด๋ฆ„ ๊ฒฐ์ • -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/views/"/> <!-- view file ๊ฒฝ๋กœ -->
            <property name="suffix" value=".jsp"/>
        </bean>
    </beans>
    • <mvc:annotation-driven/>: annotation ํ™œ์„ฑํ™”
    • <context:component-scan base-package="com.simple.web.controller"/>: component-scan ์˜ ๊ธฐ๋ณธ package ์ง€์ •.
      (์ €์˜ ๊ฒฝ์šฐ com.simple ๋ผ๋Š” ํŒจํ‚ค์ง€๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ทธ ์•ˆ์— Controller ๋ฅผ ์œ„์น˜์‹œํ‚ฌ ๊ฒƒ์ด๋ฏ€๋กœ ์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.)
    • <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">: view resolver ๋กœ view ํŒŒ์ผ์— ๋Œ€ํ•œ ์„ค์ •์„ ํ•ฉ๋‹ˆ๋‹ค.
      • <property name="prefix" value="/WEB-INF/views/"/>: view ํŒŒ์ผ์˜ ์ ‘๋‘์‚ฌ ์„ค์ •
      • <property name="suffix" value=".jsp"/>: view ํŒŒ์ผ์˜ ์ ‘๋ฏธ์‚ฌ ์„ค์ •
      • ex) view ํŒŒ์ผ ์ด๋ฆ„์ด home ์ด๋ผ๋ฉด, "home" ๋งŒ ๋ฐ˜ํ™˜ํ•ด๋„ view resolver ๋ฅผ ํ†ตํ•ด "/WEB-INF/views/home.jsp" ๋กœ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

     

     

    6) Controller ์ž‘์„ฑ

    ์ด์ œ ํ”„๋กœ์ ํŠธ ์„ค์ •์ด ๊ฑฐ์˜ ๋งˆ๋ฌด๋ฆฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

    ๋‚จ์€ ๊ฒƒ์€ Tomcat ์„ ์‹คํ–‰ํ•ด๋ณด๋Š” ๊ฒƒ์ธ๋ฐ, ์ด๋ฅผ ์œ„ํ•ด ๊ฐ„๋‹จํ•œ Controller ๋ฅผ ์ž‘์„ฑํ•ด์„œ ์š”์ฒญ์„ ์ž˜ ์ฒ˜๋ฆฌํ•˜๋Š”์ง€ ํ™•์ธํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

     

    ๋จผ์ €, com.simple.web.controller ๋ผ๋Š” ํŒจํ‚ค์ง€ ์•„๋ž˜์— SimpleController.java ๋ผ๋Š” ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

    (๊ฒฝ๋กœ/ํŒŒ์ผ ์ด๋ฆ„์€ ์ž์œ ์ด๋‚˜ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์€ dispatcherServlet.xml ์— ๋ฐ˜์˜ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.)

     

    ์ด Controller ๋Š” ๋‹ค์Œ์˜ ํ•˜๋‚˜์˜ ์š”์ฒญ๋งŒ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

    • "/" ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด "hello" ๋ผ๋Š” View ๋ฅผ ๋ฆฌํ„ด
      ์ด๋Š” ์•ž์„œ ์„ค์ •ํ•œ ๊ฒƒ์ฒ˜๋Ÿผ view resolver ์— ์˜ํ•ด "/WEB-INF/views/home.jsp" ํŒŒ์ผ์„ ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

    SimpleController.java

     

    dispatcherServlet.xml ์— ๋“ฑ๋กํ•œ view resolver ์˜ ์ ‘๋‘์‚ฌ์— ๋งž๊ฒŒ,

    WEB-INF/views ํด๋” ์•ˆ์— hello.jsp ๋ผ๋Š” ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์„œ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

     

    hello.jsp

     

    ํ•œ ๊ฐ€์ง€ ์ฃผ์˜ํ•  ์ ์€ WEB-INF/index.jsp ํŒŒ์ผ์€ ์ด์ œ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋‹ˆ ์‚ญ์ œํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    (์ด๊ฑธ ์‚ญ์ œํ•˜์ง€ ์•Š์œผ๋ฉด index.jsp ๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ฐ˜ํ™˜)

     

    index.jsp ํŒŒ์ผ ์‚ญ์ œ

     

     

    7) Tomcat ๋“ฑ๋ก ๋ฐ ์—ฐ๋™

    Tomcat ์€ ๋™์  ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•ด์ฃผ๋Š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค.

     

    ์ด์ œ Tomcat ์„ ๋“ฑ๋กํ•ด์ฃผ๊ณ  ์—ฐ๋™ํ•ด์„œ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰์‹œํ‚ฌ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    (Tomcat ์ด ๋‹ค์šด๋ฐ›์•„์ ธ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Apache-Tomcat-์ž์‹ ์˜ OS ์— ๋งž๋Š” ํŒŒ์ผ ๋‹ค์šด (์ €๋Š” zip ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์•„์„œ ์••์ถ•์„ ํ’€์–ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.))

     

     

    IDE ์šฐ์ธก ์ƒ๋‹จ์— ๋ณด๋ฉด Add Configuration ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

     

    Add Configuration

     

    ๋‹ค์Œ๊ณผ ๊ฐ™์ด Run/Debug Configurations ๊ฐ€ ๋œน๋‹ˆ๋‹ค.

    + ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ Tomcat Server ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

     

     

    ์ด๋•Œ ์ฒ˜์Œ Tomcat ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋ฉด, Tomcat ์‹คํ–‰ ํŒŒ์ผ์ด ์žˆ๋Š” ๊ฒฝ๋กœ๋ฅผ ํ†ตํ•ด Tomcat ์„ ๋“ฑ๋กํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ์ด ๊ฒฝ์šฐ, ์•„๋ž˜์˜ Application Server์— ์•„๋ฌด๋Ÿฐ ์„ ํƒ์ง€๊ฐ€ ์—†์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    ์šฐ์ธก์˜ Configure ์„ ๋ˆŒ๋Ÿฌ์„œ Tomcat ์ด ์žˆ๋Š” ํด๋” ๊ฒฝ๋กœ๋ฅผ ์„ ํƒํ•ด์ค๋‹ˆ๋‹ค.

     

     

    ์„ฑ๊ณต์ ์œผ๋กœ Tomcat ์„ ์ธ์‹ํ•˜๊ณ  ๋“ฑ๋กํ•ด์ค€ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

     

    ์•„๋ž˜์— Warning ์ด ๋œจ๋Š”๋ฐ, Fix ๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

    ๋‹จ, artifact ๋Š” (exploded) ๊ฐ€ ๋ถ™์ง€ ์•Š์€ ๊ฒƒ์„ ๊ณจ๋ผ์ค๋‹ˆ๋‹ค.

     

     

    ๊ทธ๋ฆฌ๊ณ  Deployment ์˜ ๊ฒฝ๋กœ๋ฅผ / ๋กœ ๋ฐ”๊ฟ”์ค๋‹ˆ๋‹ค.

     

     

    ์ด๋Ÿฌ๋ฉด Tomcat ์„ค์ •์ด ๋๋‚˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค!

     

     

     

    * Tomcat ํ•œ๊ธ€ ๊นจ์ง ํ•ด๊ฒฐ

     

    ์ด๋ ‡๊ฒŒ Tomcat ์˜ Log ์— ํ•œ๊ธ€์ด ๊นจ์ ธ์„œ, ๊ทธ๋ƒฅ ์˜์–ด๋กœ ๋ฐ”๊ฟจ์Šต๋‹ˆ๋‹ค.

     

    -Dfile.encoding=UTF-8 -Duser.language=en -Duser.region=us

     

    ์ด ์˜ต์…˜์„ Tomcat ์˜ VM options ์— ๋„ฃ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

     

     

    ์„ค์ •ํ•œ Optinos ์™€ ํ•จ๊ป˜ Tomcat ์ด ์‹คํ–‰๋˜์—ˆ๊ณ , ํ•œ๊ธ€ ๊นจ์ง๋„ ์—†์–ด์กŒ์Šต๋‹ˆ๋‹ค.

     

     

     

     

    8) Tomcat ์‹คํ–‰

    ์šฐ์ธก ์ƒ๋‹จ์—์„œ ๋“ฑ๋กํ•œ Tomcat ์„ ์„ ํƒํ•ด์ฃผ๊ณ , ์ดˆ๋ก์ƒ‰ Run ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด Tomcat ์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

     

     

    Tomcat ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์‹คํ–‰๋˜๋ฉด, ์ž๋™์œผ๋กœ Deployment ์—์„œ ์„ค์ •ํ•œ ๊ฒฝ๋กœ๋กœ ์›นํŽ˜์ด์ง€๋ฅผ ๋„์›Œ์ค๋‹ˆ๋‹ค.

     

    ๋‹ค์Œ๊ณผ ๊ฐ™์ด localhost:8080/ ์— hello.jsp ๊ฐ€ ์ž˜ ๋œจ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

     

    localhost:8080

     

     

     

    ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด Spring MVC ํ”„๋กœ์ ํŠธ ์„ค์ •์ด ๋๋‚ฉ๋‹ˆ๋‹ค.

     

    ์‹œํ–‰์ฐฉ์˜ค๊ฐ€ ๋งŽ์•˜์œผ๋‚˜, ์—ญ์‹œ ์ง์ ‘ ํ•ด๋ณด๋‹ˆ ๋‚ด๋ถ€ ๊ตฌ์กฐ๋ฅผ ๋” ์ž˜ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๐Ÿ‘

     

     

    ๋Œ“๊ธ€

Designed by Tistory.