开发者

set servletConfig by java

in web.xml

<servlet>
    <servlet-name>controller</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>aliases</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>contextConfigLocation&开发者_Python百科lt;/param-name>
      <param-value>classpath:spring/spring-web.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>controller</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

now I want to instantiate the servlet in java, how can I set contextConfigLocation?


Add:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>

before the filters section (you need to adjust the path) and:

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

before the servlet section

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜