为什么弹簧调度程序要加载两次?

问题描述 投票:0回答:1

最近,由于调度程序两次加载,因此我遇到了与调度程序有关的问题。我付出了很多努力来解决它,但无法解决它。我发现的与此问题相关的每个问题都表示这是与spring有关的问题,因为调度程序加载了两次,如果您使用的是最新版本,则可以解决,但我认为不是。如果可以的话,有人可以告诉我这个问题。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">

    <error-page>
    <!-- Missing login -->
    <error-code>401</error-code>
    <location>/v1/error.xhtml</location>
</error-page>
<error-page>
    <!-- Forbidden directory listing -->
    <error-code>403</error-code>
    <location>/v1/error.xhtml</location>
</error-page>
<error-page>
    <!-- Missing resource -->
    <error-code>404</error-code>
    <location>/v1/error.xhtml</location>
</error-page>
<error-page>
    <!-- Uncaught exception -->
    <error-code>500</error-code>
    <location>/v1/error.xhtml</location>
</error-page>
<error-page>
    <!-- Unsupported servlet method -->
    <error-code>503</error-code>
    <location>/v1/error.xhtml</location>
</error-page>
<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/v1/login.xhtml</location>
</error-page>
<error-page>
    <exception-type>javax.servlet.ServletException</exception-type>
    <location>/v1/login.xhtml</location>
</error-page>
<display-name>IN UI</display-name>
<welcome-file-list>
    <welcome-file>/v1/login.xhtml</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/v1/*</url-pattern>
</servlet-mapping>
<filter>
    <filter-name>ExpiresFilter</filter-name>
    <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
    <init-param>
        <param-name>ExpiresByType image</param-name>
        <param-value>access plus 10 minutes</param-value>
    </init-param>
    <init-param>
        <param-name>ExpiresByType text/css</param-name>
        <param-value>access plus 10 minutes</param-value>
    </init-param>
    <init-param>
        <param-name>ExpiresByType application/javascript</param-name>
        <param-value>access plus 10 minutes</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>ExpiresFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>
<context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>
<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
</context-param>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
              /WEB-INF/spring-servlet.xml    
    </param-value>
</context-param>
<context-param>
    <param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name>
    <param-value>6LedGUAUAAAAAGap-5zdfoh_uEVC6ccuf_oL61Be</param-value>
</context-param>
<context-param>
    <param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name>
    <param-value>6LedGUAUAAAAAK6rMd7J1LDq-utm55Oc3mo645im</param-value>
</context-param>

javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE真正com.sun.faces.config.ConfigureListenerorg.springframework.web.context.ContextLoaderListener

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<mime-mapping>
    <extension>xhtml</extension>
    <mime-type>application/xml</mime-type>
</mime-mapping>

java spring web.xml
1个回答
0
投票

确定,在web.xml中发现了一些问题,因为您两次使用请求上下文侦听器加载上下文,一次使用Dispatcher Servlet加载上下文。我认为在加载Request Context Listener时无需加载Dispatcher Servlet,因此请从web.xml:]中删除它

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

它将解决您的问题。有关更多详细信息,请参见:contextloaderlistener vs dispatcherservlet

© www.soinside.com 2019 - 2024. All rights reserved.