ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฐ˜์‘ํ˜•
์„ค์ •ํŒŒ์ผ ๋ชฐ์•„๋„ฃ๊ธฐ

์ด ๋ถ€๋ถ„์€ ๊ฐœ์ธ์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๋ถ€๋ถ„์ด๋‹ˆ ํ•ด์ฃผ์–ด๋„ ๋˜๊ณ  ์•ˆํ•ด์ฃผ์–ด๋„ ๋˜๊ณ !

์„ค์ •ํŒŒ์ผ์ด ๋‚˜๋ˆ„์–ด์ ธ ์žˆ์œผ๋ฉด ๋ณด๊ธฐ ํž˜๋“œ๋‹ˆ๊นŒ resourcesํด๋”์— ๋ชฐ์•„ ๋„ฃ์—ˆ๋‹ค.

์Šคํ”„๋ง ์„ค์ • ํŒŒ์ผ์ด๋‹ˆ๊นŒ spring์ด๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ํด๋”๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค.

๋‹ค์Œ root-context.xml ํŒŒ์ผ๊ณผ servlet.xml ํŒŒ์ผ์„ spring ํด๋”๋กœ ์˜ฎ๊ธด๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์Šคํ”„๋ง ์„ค์ •ํŒŒ์ผ๋“ค์˜ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•ด์ฃผ์—ˆ๋‹ค.

  • root-context.xml -> mvc-config.xml
  • servlet-context.xml -> servlet-config.xml

 

 

web.xml

์›น์— ๊ด€๋ จํ•œ ์„ค์ •์„ ๋ชจ์•„๋‘” ํŒŒ์ผ์ด๋‹ค.

์„ค์ •ํŒŒ์ผ์˜ ๊ฒฝ๋กœ๋ฅผ ๋ฐ”๊ฟ”๋†“์•˜์œผ๋‹ˆ web.xml์—์„œ ๋ณ€๊ฒฝ๋œ ๊ฒฝ๋กœ๋กœ ์ž‘์„ฑํ•ด์ค€๋‹ค.

์‰ฝ๊ฒŒ resources ํด๋”๋กœ ๋“ค์–ด๊ฐ€๋Š” ๋ฐฉ๋ฒ•์€ class:/๋ฅผ ์ด์šฉํ•œ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
    <!-- DB์„ค์ • ๋“ฑ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ์„ค์ •์„ ๊ด€๋ฆฌํ•  xml ์„ค์ • ๊ฒฝ๋กœ ์ง€์ • (root-context.xml) -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <!-- ๊ฒฝ๋กœ ๋ณ€๊ฒฝ (๊ธฐ์กด๊ฒฝ๋กœ : /WEB-INF/spring/root-context.xml -->
        <param-value>classpath:/spring/mvc-config.xml</param-value>
    </context-param>
    
    
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
 
    <!-- Dispatcher Servlet ์„ค์ • xmlํŒŒ์ผ ๊ฒฝ๋กœ ์ง€์ • (servlet-context.xml) -->
    <servlet>
        <!-- ์„œ๋ธ”๋ฆฟ ํด๋ž˜์Šค์˜ ์ด๋ฆ„์€ appServlet์ด๋‹ค. -->
        <servlet-name>appServlet</servlet-name>
        <!-- ํด๋ž˜์Šค์˜ ์œ„์น˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. -->
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- ์ดˆ๊ธฐ ํŒŒ๋ผ๋ฏธํ„ฐ (์ดˆ๊ธฐ๊ฐ’) ์ด๋ฆ„๊ณผ ๊ฐ’์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ง€์ •ํ•˜๊ฒ ๋‹ค. -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <!-- ๊ฒฝ๋กœ ๋ณ€๊ฒฝ (๊ธฐ์กด ๊ฒฝ๋กœ : /WEB-INF/spring/appServlet/servlet-context.xml -->
            <param-value>classpath:/spring/servlet-config.xml</param-value>
        </init-param>
        <!-- 1 : ๋ˆ„๊ตฌ๋ณด๋‹ค ๋จผ์ € ํ˜ธ์ถœํ•˜๊ฒ ๋‹ค. -->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- ์„œ๋ธ”๋ฆฟ URL Mapping ์„ค์ • -->
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <!-- /๋กœ ์‹œ์ž‘ํ•˜๋Š” url์ด ๋“ค์–ด๊ฐ€๋ฉด ์„œ๋ธ”๋ฆฟ์„ ์ž‘๋™ํ•˜๊ฒ ๋‹ค. ๋ชจ๋“  ์š”์ฒญ์ด ๋“ค์–ด๊ฐ€์•ผํ•˜๊ธฐ ๋–„๋ฌธ์— /๋กœ ์ž‘์„ฑ -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    
    <!-- ํ•œ๊ธ€ ์ฒ˜๋ฆฌ ์ฝ”๋“œ -->
    <filter>
        <filter-name>encodingFilter</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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <!-- ์œ„์— ์ง€์ •ํ•œ encodingFilter์ด๋ฆ„์„ ๋ชจ๋“  ํŒจํ„ด์— ์ ์šฉ -->
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
 
</web-app>
 
 
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€