java - 为什么 Spring 调度程序加载两次?

标签 java spring web.xml

最近,我遇到了与调度程序相关的问题,因为它加载了两次。我付出了很多努力来解决它,但无法修复它。我发现与这个问题相关的每个问题都说这是一个与 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.ConfigureListener org.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>

最佳答案

好的,我在 web.xml 中发现了一些问题,因为您加载上下文两次,一次使用 Request Context Listener,一次使用 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

关于java - 为什么 Spring 调度程序加载两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58360971/

相关文章:

java - MapStruct 不会通过 Spring-boot 测试 Gradle Junit5 自动写入

java - 如何在外部主类中访问在tomcat中运行的现有应用程序上下文

quartz-scheduler - web.xml 中的 Quartz 属性文件配置及其位置

java - 如何禁用 WebApplicationInitializer 类的 Servlet 类路径扫描,但仍显式使用我自己的实例?

java - 具有物理特性的快速而肮脏的平台游戏在移动平台时会出现错误

java - 对 int 类型进行比较

java客户端应用程序 session 恢复

java - Spring Data Reactive Elasticsearch错误/警告

java - 如何为@CachePut定义多个键?

java - 无法从jetty访问index.html