sitelink1  
sitelink2  
sitelink3  
extra_vars6  

·미리보기 | 소스복사·
1.<web-app>  
2.  
3.    <display-name>Spring JPetStore</display-name>  
4.  
5.    <description>Spring JPetStore sample application</description>  
6.영어를 대충 번역해보면 WebAppRootListener 또는 Log4jConfigListener 에 의해 제공되는 이 web 어플의 root 디렉토리가 되는 시스템 프로퍼티의 키란다.
http://www.springframework.org/docs/api/org/springframework/web/util/WebAppRootListener.html 여기까지 가서 클래스를 살펴보니 default key는 webapp.root란다.
위의 내용에서는 webAppRootKey의 값이 petstore.root 라고 나와 있다.
현재 파일의 96라인을 보면 서블릿 매핑정보에 petstore가 적혀 있다.

7.    <!--   
8.      - Key of the system property that should specify the root directory of this   
9.      - web app. Applied by WebAppRootListener or Log4jConfigListener.   
10.      -->  
11.    <context-param>  
12.        <param-name>webAppRootKey</param-name>  
13.        <param-value>petstore.root</param-value>  
14.    </context-param>  
15.내용을 봐서는 log4j.properties 환경화일을 읽어들이는 문장인 것 같다.
대부분 log4j.properties 파일을 저 위치에 두니까 수정할 일은 없겠다.

    <!--   
16.      - Location of the Log4J config file, for initialization and refresh checks.   
17.      - Applied by Log4jConfigListener.   
18.      -->  
19.    <context-param>  
20.        <param-name>log4jConfigLocation</param-name>  
21.        <param-value>/WEB-INF/log4j.properties</param-value>  
22.    </context-param>  
23.조금 중요해 보이는 구문이다.
스프링에서는 POJO빈이라는 것이 나온다.
2000년 9월부터 마틴파울러에 의해 언급되어진 POJO(Plain Old Java Object)는 순수 자바클래스를 이야기한다.
이 POJO 빈의 생명주기를 관리하는 정보를 담고 있는 것이 dataAccessCont ext-local.xml 과 applicationContext.xml 파일이고
이러한 정보를 담고 있는 것을 처리해 주는 클래스가 listener 엘리먼트에 정의되어진 ContextLoaderListener 이란 spring 프레임워크의 클래스이다.
주석에 보면 싱글 데이터베이스를 위해서 "/WEB-INF/dataAccessContext-local.xml" 를 인클루드 할 수 있고,
더블 데이터베이스를 위해서 "/WEB-INF/dataAccessContext-jta.xml" 를 인클루드 할 수 있다고 한다.
위 두 xml 화일은 추후에 분석해봐야겠다.

    <!--   
24.      - Location of the XML file that defines the root application context.   
25.      - Applied by ContextLoaderServlet.   
26.        -   
27.        - Can include "/WEB-INF/dataAccessContext-local.xml" for a single-database   
28.        - context, or "/WEB-INF/dataAccessContext-jta.xml" for a two-database context.   
29.      -->  
30.    <context-param>  
31.        <param-name>contextConfigLocation</param-name>  
32.        <param-value>  
33.            /WEB-INF/dataAccessContext-local.xml  /WEB-INF/applicationContext.xml   
34.        </param-value>  
35.        <!--   
36.        <param-value>  
37.            /WEB-INF/dataAccessContext-jta.xml  /WEB-INF/applicationContext.xml   
38.        </param-value>  
39.        -->  
40.    </context-param>  
41.위에 언급한 log4jConfigLocation 과 관련이 있어 보인다.
JBoss를 사용하고 있으면 주석을 떼라는 말이 있다.
include문과 logging 설정에 관련된 내용을 보면 일반적인 log4j.properties 파일의 위치가 아닐 경우를 이야기 하는거 같기도 하고

    <!--   
42.      - Configures Log4J for this web app.   
43.      - As this context specifies a context-param "log4jConfigLocation", its file path   
44.      - is used to load the Log4J configuration, including periodic refresh checks.   
45.      -   
46.      - Would fall back to default Log4J initialization (non-refreshing) if no special   
47.      - context-params are given.   
48.      -   
49.      - Exports a "web app root key", i.e. a system property that specifies the root   
50.      - directory of this web app, for usage in log file paths.   
51.      - This web app specifies "petclinic.root" (see log4j.properties file).   
52.      -->  
53.    <!-- Leave the listener commented-out if using JBoss -->  
54.    <!--   
55.    <listener>  
56.        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  
57.    </listener>  
58.    -->  
59.       
60.    <!--   
61.      - Loads the root application context of this web app at startup,   
62.      - by default from "/WEB-INF/applicationContext.xml".   
63.        - Note that you need to fall back to Spring's ContextLoaderServlet for   
64.        - J2EE servers that do not follow the Servlet 2.4 initialization order.   
65.        -   
66.      - Use WebApplicationContextUtils.getWebApplicationContext(servletContext)   
67.      - to access it anywhere in the web application, outside of the framework.   
68.      -   
69.      - The root context is the parent of all servlet-specific contexts.   
70.      - This means that its beans are automatically available in these child contexts,   
71.      - both for getBean(name) calls and (external) bean references.   
72.      -->  
73.    <listener>  
74.        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
75.    </listener>  
76.

드디어 servlet 과 servlet-mapping 정보가 나왔다.
매핑정보에 보면 모든 .do 호출에 대해서 action 서블릿이 아닌 petstore 서블릿으로 매핑하고 있다.
petstore 서블릿 이름에는 org.springframework.web.servlet.DispatcherServlet 클래스로 링크되어 있다.
스트럿츠의 ActionServlet 이 아닌 스프링의 DispatcherServlet 클래스를 통해서 스프링 MVC를 이용하겠다.

등록된 Handler정보에 따라 클라이언트의 요청을 dispatches(분류?) 해준다.
기본적으로 Handler매핑 정보를 담고 있는 설정 화일은 "{servlet-name}-servlet.xml"형태로 jpetstore 핸들러 설정 화일은 "petstore-servlet.xml"이다.

load-on-startup 이라는 태그가 보인다. 해당 서블릿의 init 되는 순서를 의미한다.
톰캣 서버가 시작하는 시점은 아니고, 컨텍스트의 웹 애플리케이션이 톰캣 서버에 의해 인식되는 시점이다.
숫자가 음의 정수인 경우: 그 서블릿에 접근될 때 (즉, load-on-startup 엘리먼트가 없는 경우와 동일함)
0 이거나 양의 정수인 경우: 그 서블릿이 배치(deploy)될 때 (즉, 컨텍스트가 인식될 때) 숫자가 작은 것 부터 먼저 로딩된다.
서블릿에 들어올때 맨처음 실행되는 init()메소드를 호출함으로써 한번 로드된 메모리나 풀.그리고 예를 들어서 struts_config같은 것들을 스타트시 한번 로드해둔다.
init()메소드는 한번 호출되면 차 후에는 destroy될때까지 그안에 있는 로직이 메모리에 정적으로 박혀버린다고 생각하면 되겠다.
참고로 struts의 ActionServlet에서 <load-on-startup>0</load-on-startup>으로 하고 나중에 *.do로 들어갈때는 맨처음 느리다가 나중에는 빨라지는것을 볼 수 있다.
다음 영문은 방금 설명한 load-on-startup 태그에 대한 관련 내용이다. 시간있슴 해석해보자.

The load-on-startup element indicates that this servlet should be
loaded (instantiated and have its init() called) on the startup
of the web application. The optional contents of
these element must be an integer indicating the order in which
the servlet should be loaded. If the value is a negative integer,
or the element is not present, the container is free to load the
servlet whenever it chooses. If the value is a positive integer
or 0, the container must load and initialize the servlet as the
application is deployed. The container must guarantee that
servlets marked with lower integers are loaded before servlets
marked with higher integers. The container may choose the order
of loading of servlets with the same load-on-start-up value.

77.    <!--   
78.      - Spring web MVC servlet that dispatches requests to registered handlers.   
79.      - Has its own application context, by default defined in "{servlet-name}-servlet.xml",   
80.      - i.e. "petstore-servlet.xml" in this case.   
81.      -   
82.      - A web app can contain any number of such servlets.   
83.      - Note that this web app has a shared root application context, serving as parent   
84.      - of all DispatcherServlet contexts.   
85.      -->  
86.    <servlet>  
87.        <servlet-name>petstore</servlet-name>  
88.        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
89.        <load-on-startup>2</load-on-startup>  
90.    </servlet>  
91.  
92.    <!--   
93.      - Struts servlet that dispatches requests to registered actions.   
94.        - Reads its configuration from "struts-config.xml".   
95.        -   
96.        - A web app can just contain one such servlet.   
97.        - If you need multiple namespaces, use Struts' module mechanism.   
98.    -->  
99.    <servlet>  
100.        <servlet-name>action</servlet-name>  
101.        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>  
102.        <load-on-startup>3</load-on-startup>  
103.    </servlet>  
104.Spring의 MVC로써 DispatcherServlet에 의해 WEB-INF/remoting-servlet.xml 파일에 대응한다.

    <!--   
105.        - Dispatcher servlet definition for HTTP remoting via Hessian, Burlap, and   
106.        - Spring's HTTP invoker (see remoting-servlet.xml for the controllers).   
107.        -->  
108.    <servlet>  
109.        <servlet-name>remoting</servlet-name>  
110.        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
111.        <load-on-startup>4</load-on-startup>  
112.    </servlet>  
113.  
114.    <!--   
115.        - Servlet definition for Web Service remoting via Apache Axis   
116.        - (see server-config.wsdd for Axis configuration).   
117.        -->  
118.    <servlet>  
119.        <servlet-name>axis</servlet-name>  
120.        <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>  
121.        <load-on-startup>5</load-on-startup>  
122.    </servlet>  
123.  
124.    <!--   
125.        - Dispatcher servlet mapping for the main web user interface.   
126.        - Either refering to "petstore" for the Spring web MVC dispatcher,   
127.        - or to "action" for the Struts dispatcher.   
128.        -   
129.        - Simply comment out the "petstore" reference in favour of "action"   
130.        - to switch from the Spring web tier to the Struts web tier.   
131.        -->  
132.    <servlet-mapping>  
133.        <servlet-name>petstore</servlet-name>  
134.        <!--  
135.        <servlet-name>action</servlet-name>  
136.        -->  
137.        <url-pattern>*.do</url-pattern>  
138.    </servlet-mapping>  
139.  
140.    <!--   
141.        - Dispatcher servlet mapping for HTTP remoting via Hessian, Burlap, and   
142.        - Spring's HTTP invoker (see remoting-servlet.xml for the controllers).   
143.        -->  
144.    <servlet-mapping>  
145.        <servlet-name>remoting</servlet-name>  
146.        <url-pattern>/remoting/*</url-pattern>  
147.    </servlet-mapping>  
148.  
149.    <!--   
150.        - Servlet mapping for Web Service remoting via Apache Axis   
151.        - (see server-config.wsdd for Axis configuration).   
152.        -->  
153.    <servlet-mapping>  
154.        <servlet-name>axis</servlet-name>  
155.        <url-pattern>/axis/*</url-pattern>  
156.    </servlet-mapping>  
157.  
158.    <welcome-file-list>  
159.        <welcome-file>index.html</welcome-file>  
160.    </welcome-file-list>  
161.  
162.    <!--   
163.      - Reference to main database.   
164.        - Only needed for JTA (dataAccessContext-jta.xml).   
165.        -->  
166.    <!--   
167.    <resource-ref>  
168.        <res-ref-name>jdbc/jpetstore</res-ref-name>  
169.        <res-type>javax.sql.DataSource</res-type>  
170.        <res-auth>Container</res-auth>  
171.    </resource-ref>  
172.    -->  
173.  
174.</web-app>