Where is the exact location of spring config file and web.xml?

后端 未结 2 2103
滥情空心
滥情空心 2021-02-10 00:19

Getting the Class Not Found Exception for DispatcherServlet while rendering index.jsp which is in WEB-CONTENT/WEB-INF/jsp/index.jsp

Following are how the project is stru

相关标签:
2条回答
  • 2021-02-10 00:26

    From the documentation:

    Upon initialization of a DispatcherServlet, Spring MVC looks for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application and creates the beans defined there, overriding the definitions of any beans defined with the same name in the global scope.

    So placing abc-servlet.xml within WEB-INF should allow the dispatcher servlet to pick up your configuration.

    If you didn't want your dispatcher servlet to use the default name or wanted it to reside in another directory besides WEB-INF you would specify this configuration in web.xml. The location and name of the dispatcher servlets configuration can be changed by setting the contextConfigLocation init-param within the DispatcherServlet

    <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>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    

    This information can be found within the Spring Documentation

    0 讨论(0)
  • 2021-02-10 00:37

    web.xml is placed under WEB-INF and then in that you can refer your spring xml like this:

    <servlet>
        <servlet-name>myservlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/abc-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    
    0 讨论(0)
提交回复
热议问题