7 Mayıs 2018 Pazartesi

SpringMVC ContextLoaderListener Sınıfı

Giriş
ApplicationContext'i ilklendirmek için kullanılır. Açıklaması şöyle.
For a more complex Spring application, where you have multiple DispatcherServlet defined, you can have the common Spring configuration files that are shared by all the DispatcherServlet defined in the ContextLoaderListener:
Örnek
Şöyle yaparız.
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:spring/common-config.xml</param-value>
</context-param>
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener
  </listener-class>
</listener>

<servlet>
  <servlet-name>mvc1</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/mvc1-config.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet>
  <servlet-name>mvc2</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/mvc2-config.xmll</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
Örnek
Şöyle yaparız.
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
    /WEB-INF/applicationContext.xml
    /WEB-INF/database1Context.xml
    /WEB-INF/database2Context.xml
  </param-value>
  </context-param>

Hiç yorum yok:

Yorum Gönder