복붙노트

[SPRING] Spring 3 MVC 디스패처 xml 및 applicationContext xml

SPRING

Spring 3 MVC 디스패처 xml 및 applicationContext xml

나는 봄 MVC 애플리케이션을 처음으로 만들었다.

마치 서버를 시작할 때 applicationContext.xml이 mvc 컨트롤러를 실행하기 전에 처음으로로드됩니다. 이것이 내가 원하는거야.

하지만 일단 컨텍스트로로드 된 컨트롤러를 실행하면 : dispatcher.xml의 component-scan .... applicationContext.xml이 다시로드되는 것을 보게됩니다. 왜 이런 일이 일어나고 어떻게 비활성화합니까? applicationContext.xml을 한 번만 실행하면됩니다.

컨트롤러를 실행 한 직후에 로그를 볼 수 있습니다.

ClassPathXmlA I org.springframework.context.support.AbstractApplicationContext prepareRefresh Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@65cb65cb: startup date [Tue Feb 15 16:29:21 EST 2011]; root of context hierarchy
XmlBeanDefini I org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions Loading XML bean definitions from class path resource [WEB-INF/applicationContext.xml]

나는 이것이 나의 jms DefaultMessageListenerContainer가 두 번 만들어 지기도한다고 생각한다.

감사

xxxdispatcher-servlet.xml

<context:component-scan base-package="com.something.web" />
<mvc:annotation-driven />

<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<mvc:interceptors>
<bean class="com.something.SomeInterceptor" />
</mvc:interceptors>

<mvc:resources mapping="/js/**" location="/js/" />

<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <property name="exceptionMappings">
    <props>
        <prop key="java.lang.Exception">common/error</prop>
    </props>
    </property>
    <property name="warnLogCategory" value="abcdefg"/>  
</bean>

applicationContext.xml

<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/application.properties" />
</bean>

<!-- Local Data Holder -->
<bean id="propertyHolder" class="com.common.PropertyHolder">
<property name="baseURL" value="${url.base}" />
</bean>

<bean id="messageListener" class="com.something.SomeListener" />

<bean id="xxxDAO"
    class="com.XXXDAOImpl"
    scope="prototype">
    <property name="dataSource" ref="dataSourceQA" />
</bean>

<bean id="xxxServiceTarget" class="com.XXXServiceImpl">
    <property name="xxxDAO" ref="xxxDAO"/>
</bean>

<bean id="xxxService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="txManager"/>
    <property name="target" ref="xxxServiceTarget"/>
    <property name="transactionAttributes">
        <props>
            <prop key="*">PROPAGATION_REQUIRED</prop>
        </props>
    </property>
</bean>

<!-- and this is the message listener container -->
<bean id="jmsContainer"
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="xxxCF" />
    <property name="destination" ref="xxxInboundQueue" />
    <property name="messageListener" ref="messageListener" />
</bean>

ВЕБ.хмл

<servlet>
    <servlet-name>xxxdispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>xxxdispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

제어 장치

  @Controller
    public class XXXController {

        @Autowired
        private IXXXService xxxService;

        @RequestMapping("/xxx")
        public String xxxHandler() throws Exception {

            return "xxxView";
        }

해결법

  1. ==============================

    1.Web.xml에서 ContextLoaderListener를 제거하십시오. 컨텍스트가 두 번 만들어지는 이유라고 생각합니다.

    Web.xml에서 ContextLoaderListener를 제거하십시오. 컨텍스트가 두 번 만들어지는 이유라고 생각합니다.

  2. from https://stackoverflow.com/questions/5009901/spring-3-mvc-dispatcher-xml-and-applicationcontext-xml by cc-by-sa and MIT license