Spring boot with Spring web更新spring boot版本后无法加载JSP

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

最近我将 Spring boot 版本从 2.3.1.RELEASE 更新到 2.5.12.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.12</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

更改版本后,只需稍作修改,我就可以按原样运行代码。 从 STS 运行时,此应用程序运行良好。

运行 mvn clean;mvn install 并生成构建后,当我使用 java -jar 命令启动此应用程序时,应用程序成功运行但无法返回 JSP 页面。

我还在之前版本的 application.properties 中添加了以下代码。

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp

我尝试在我的 pom.xml 文件中添加 spring-boot-starter-tomcat 依赖项。我的 pom.xml 中确实已经有 tomcat-embed-jasper(已提供)和 jstl(已提供)依赖项

在调试模式下运行时出现以下错误:

我尝试用 jsp 重命名 WEB-INF 文件夹,但这不起作用。

也试过 mvn:spring-boot 命令但同样的问题。

文本格式的日志:

2023-04-16 16:27:31,452 INFO  [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.FrameworkServlet: 

Initializing Servlet 'dispatcherServlet'
2023-04-16 16:27:31,453 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.DispatcherServlet: Detected StandardServletMultipartResolver
2023-04-16 16:27:31,453 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.DispatcherServlet: Detected SessionLocaleResolver
2023-04-16 16:27:31,454 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.DispatcherServlet: Detected FixedThemeResolver
2023-04-16 16:27:31,455 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.DispatcherServlet: Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@4037cdb0
2023-04-16 16:27:31,455 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.DispatcherServlet: Detected org.springframework.web.servlet.support.SessionFlashMapManager@2dd08ff1
2023-04-16 16:27:31,455 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.FrameworkServlet: enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2023-04-16 16:27:31,455 INFO  [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.FrameworkServlet: Completed initialization in 2 ms
2023-04-16 16:27:31,478 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.FilterChainProxy: Securing GET /login
2023-04-16 16:27:31,485 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.context.SecurityContextPersistenceFilter: Set SecurityContextHolder to empty SecurityContext
2023-04-16 16:27:31,489 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.authentication.AnonymousAuthenticationFilter: Set SecurityContextHolder to anonymous SecurityContext
2023-04-16 16:27:31,509 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.access.intercept.AbstractSecurityInterceptor: Authorized filter invocation [GET /login] with attributes [permitAll]
2023-04-16 16:27:31,511 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.FilterChainProxy$VirtualFilterChain: Secured GET /login
2023-04-16 16:27:31,517 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.core.log.LogFormatUtils: GET "/login", parameters={}
2023-04-16 16:27:31,524 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.handler.AbstractHandlerMapping: Mapped to com.meds.controller.LoginController#login(HttpServletRequest, HttpServletResponse, Model, String, String, String)
2023-04-16 16:27:31,590 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.view.ContentNegotiatingViewResolver: Selected 'text/html' given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.7, */*;q=0.8]
2023-04-16 16:27:31,591 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.view.AbstractView: View name 'login', model {login=true}
2023-04-16 16:27:31,598 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.view.InternalResourceView: Forwarding to [/WEB-INF/views/login.jsp]
2023-04-16 16:27:31,603 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper: Did not store anonymous SecurityContext
2023-04-16 16:27:31,605 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.FrameworkServlet: Completed 404 NOT_FOUND
2023-04-16 16:27:31,609 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper: Did not store anonymous SecurityContext
2023-04-16 16:27:31,609 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.context.SecurityContextPersistenceFilter: Cleared SecurityContextHolder to complete request
2023-04-16 16:27:31,610 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.FilterChainProxy: Securing GET /error
2023-04-16 16:27:31,610 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.context.SecurityContextPersistenceFilter: Set SecurityContextHolder to empty SecurityContext
2023-04-16 16:27:31,610 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.authentication.AnonymousAuthenticationFilter: Set SecurityContextHolder to anonymous SecurityContext
2023-04-16 16:27:31,610 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.security.web.FilterChainProxy$VirtualFilterChain: Secured GET /error
2023-04-16 16:27:31,611 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.core.log.LogFormatUtils: "ERROR" dispatch for GET "/error", parameters={}
2023-04-16 16:27:31,612 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.handler.AbstractHandlerMapping: Mapped to com.meds.controller.CustomErrorController#handleError(HttpServletRequest)
2023-04-16 16:27:31,617 DEBUG [http-nio-127.0.0.1-9090-exec-1] org.springframework.web.servlet.view.ContentNegotiatingViewResolver: Selected 'text/html' given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.7, */*;q=0.8]

在 chrome 上运行时的输出:

spring spring-boot spring-boot-2.6.0
© www.soinside.com 2019 - 2024. All rights reserved.