티스토리 뷰

728x90

 

1. web.xml : 설정을 위한 설정파일이다. 배포 기술자로써 영어로는 DD(Deployment Descriptor) 이다.

이 파일은 WAS(Web Application Server)가 최초 구동될 때 즉 톰켓이 최초 구동될 때 web.xml을 읽고 그에 해당하는 설정을 구성한다. 즉 각종 설정을 위한 설정파일이라고 할 수 있다.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
	<distributable/>

    <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>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>*.do</url-pattern>
        <url-pattern>*.json</url-pattern>
        <url-pattern>/cgi-bin/cert-seal4</url-pattern>
    </filter-mapping>

    <!-- spring context loading -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:spring/context/context-*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- servlet context loading -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/servlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
        <url-pattern>*.json</url-pattern>
        <url-pattern>/cgi-bin/cert-seal4</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>360</session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>

   <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/error.sg</location>
    </error-page>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>NoAccess</web-resource-name>
            <url-pattern>/*</url-pattern>
              <http-method>HEAD</http-method>
              <http-method>PUT</http-method>
              <http-method>DELETE</http-method>
              <http-method>TRACE</http-method>
              <http-method>OPTIONS</http-method>
              <http-method>PATCH</http-method>
        </web-resource-collection>
        <auth-constraint/>
    </security-constraint>
 

1) ContextLoaderListener에 의해서 만들어지는 Root WebApplicationContext

2) DispatcherServlet에 의해서 만들어지는 WebApplicationContext

- Root WebApplicationContext 이름 그대로 최상단에 위치한 Context 이다

- 서비스 계층이나 DAO를 포함한, 웹 환경에 독립적인 빈들을 담아둔다.

- 서로 다른 서블릿컨텍스트에서 공유해야 하는 빈들을 등록해놓고 사용할 수 있다.

- Servlet context에 등록된 빈들을 이용 불가능하고 servlet context와 공통된 빈이 있다면 servlet context 빈이 우선된다.

- WebApplication 전체에 사용가능한 DB연결, 로깅 기능들이 이용된다.

- ContextLoaderListener: 스프링의 root WebApplicationContext를 시작 시키기 위한 Bootstrap listener

-DispatcherServlet 은 각가 별도의 webapplicationcontext를 생성한다.

- ContextLoaderListener 와 DispatcherServlet 은 각각 webapplicationcontext 를 생성하는데

ContextLoaderListener 가 생성한 컨텍스트가 root 컨텍스트가 되고 DispatcherServlet 생성한 인스턴스는

root 컨텍스트를 부모로 하는 자식 컨텍스트가 된다.

 

>> 참고 할 자료

2022.10.24 - [[공부] 원리] - [Spring] 컨테이너

 

[Spring] 컨테이너

1. 컨테이너: 특정 객체의 생성과 관리를 담당하며 객체 운용에 필요한 기능을 제공 (스프링도 일종의 컨테이너) ​ 2. 스프링 컨테이너 종류 BeanFactory: applicationContext.xml에 등록된 bean객체를 생성,

gajy.tistory.com


 

2. servlet-context.xml : DispatcherServlet과 관련된 설정을 한다. ViewResolver, HanderMapping, Controllers 등이 생성된다.

 

<?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"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <mvc:annotation-driven/>

    <mvc:default-servlet-handler/>

    <mvc:resources location="/favicon.ico" mapping="/favicon.ico"/>

    <context:component-scan base-package="com.test.service.test.controller" />
    <context:component-scan base-package="com.test.service.common.handler" />

    <!-- Resolver setting -->
    <!-- tiles Resolver-->
    <bean id="tilesviewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
        <property name="order" value="0" />
    </bean>

    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles/layout.xml</value>
            </list>
        </property>
    </bean>

    <!-- BeanName Resolver -->
    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
        <property name="order" value="1"/>
    </bean>

    <!-- jsp Resolver -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="order" value="2" />
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/view/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- FileUpload Resolver -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="10000000" />
        <property name="defaultEncoding" value="utf-8" />
    </bean>
    <!-- Resolver setting -->

    <!-- FileDownload View -->
    <bean id="fileDownloadView" class="com.test.service.common.view.FileDownloadView" />

    <!-- ExcelDownload View  -->
    <bean id="excelDownloadView" class="com.test.service.common.view.ExcelDownloadView" />

    <!-- StreamDownload View -->
    <bean id="streamDownloadView" class="com.test.service.common.view.StreamDownloadView" />

    <mvc:interceptors>
        <bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
            <property name="cacheSeconds" value="0" />
            <property name="useExpiresHeader" value="true" />
            <property name="useCacheControlHeader" value="true" />
            <property name="useCacheControlNoStore" value="true" />
        </bean>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <mvc:exclude-mapping path="/error*" />
            <mvc:exclude-mapping path="/login/**" />
            <bean class="com.kica.ssl.common.interceptor.LoginCheckInterceptor" />
        </mvc:interceptor>
        <bean class="com.test.service.common.interceptor.ParameterLogInterceptor" />
        <bean class="com.test.service.common.interceptor.CsrfInterceptor" />
    </mvc:interceptors>
</beans>
 
 

 

3. context-*.xml: ContextLoaderListener 와 DispatcherServlet 은 각각 webapplicationcontext 를 생성하는데

ContextLoaderListener 가 생성한 컨텍스트가 root 컨텍스트가 되고 DispatcherServlet 생성한 인스턴스는 root 컨텍스트를 부모로 하는 자식 컨텍스트가 된다.

자식 컨텍스트들은 root 컨텍스트의 설정 빈을 사용 할 수 있다.

그러기에 ContextLoaderListener 을 이용 공통빈 설정 가능.

예를 들어 DispatcherServlet을 두개를 사용하고, 같은 service, dao를 사용가능.

<?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:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

    <context:component-scan base-package="com.test.service.partner.service" />
    <context:component-scan base-package="com.est.service.partner.dao.common" />
    <context:component-scan base-package="com.est.service.common.component" />

    <!-- propeti util -->
    <util:properties id="common" location="classpath:/property/common.properties" />
    <util:properties id="mail" location="classpath:/property/mail.properties" />
    <util:properties id="payment" location="classpath:/property/payment.properties" />
</beans>
 

 

 

728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
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