Spring 설정 파일 분리 - dispatcher-servlet.xml

    하나로 된 파일을 여러개의 xml로 나누기

    프로젝트를 여러사람이 만들경우 동기화할 경우 문제가 생겨 각자 맡은 역할을 나눠서 작업하기 위해서 나눈다.

    혼자 만들 경우에도 나눠서 설정을 해주는게 좋다.

    servlet-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            https://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/mvc
            https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    	
    	    <bean name="/index" class="com.newlecture.web.controller.IndexController" />  
    	 <bean name="/notice/list" class="com.newlecture.web.controller.notice.ListController" >
    	 	<property name="noticeService" ref="noticeService"/>
    	 </bean> 
    	  <bean name="/notice/detail" class="com.newlecture.web.controller.notice.DetailController" />   
    
    	<bean
    		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    		<property name="viewClass"
    			value="org.springframework.web.servlet.view.tiles3.TilesView" />
    		<property name="order" value="1" />
    	</bean>
    
    	<bean
    		class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    		<property name="definitions" value="/WEB-INF/tiles.xml" />
    	</bean>
    	
    	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix" value="/WEB-INF/view/"></property>
    		<property name="suffix" value=".jsp"></property>
    		<property name="order" value="2" />
    	</bean>
    	
    	<mvc:resources location="/static/" mapping="/**"></mvc:resources>
    	
    	
    </beans>

     

    service-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            https://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/mvc
            https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    	
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
    		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    		<property name="url" value="jdbc:oracle:thin:@localhost:1521/xepdb1" />
    		<property name="username" value="NEWLEC" />
    		<property name="password" value="11111" />
    	</bean>
    	
    	<bean id="noticeService" class="com.newlecture.web.service.jdbc.JDBCNoticeService" >
    		<property name="dataSource" ref="dataSource"></property>
    	</bean>
    	
    </beans>

     

    설정 적용시키기 web.xml

    init-param 사용

    listener class 사용 - tomcat이 실작되거나 끝날때 세션이 시작되거나 끝날때 이벤트 처리를 위해 사용

     

    <load-on-startup> - tomcat이 시작될때 servlet을 laod하고 싶을 경우 숫자는 우선순위를 나타낸다.

    <async-supported> - 비동기적으로 load되는 것을 원할 경우

     

    web.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"
      metadata-complete="true">
    	
      <listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			/WEB-INF/spring/service-context.xml
    			/WEB-INF/spring/security-context.xml
    		</param-value>
    	</context-param>
    	
      <servlet>
      	<servlet-name>dispatcher</servlet-name>
    	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    	<init-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/spring/servlet-context.xml</param-value>
    	</init-param>
    	<load-on-startup>1</load-on-startup>
    	<async-supported>true</async-supported>
      </servlet>
      <servlet-mapping>
      	<servlet-name>dispatcher</servlet-name>
      	<url-pattern>/</url-pattern>
      </servlet-mapping>
    
    
      <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description>
    
    </web-app>
    • 네이버 블러그 공유하기
    • 네이버 밴드에 공유하기
    • 페이스북 공유하기
    • 카카오스토리 공유하기
    loading