gpt4 book ai didi

java - Java Spring Boot:Servlet [dispatcherServlet]的Servlet.service()抛出异常

转载 作者:行者123 更新时间:2023-12-01 06:05:43 25 4
gpt4 key购买 nike

我正在尝试编写一个Spring Boot应用程序来为AngularJS应用程序提供一个文件“ index.html”。我有以下课程:

应用程序

@SpringBootApplication
public class Application
extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(Application.class);
}

public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
}


BaseController.java

@Controller
public class BaseController
{
// Map all urls to this method aside from ones starting with api
@RequestMapping(value = "/**")
public String getIndexHtml()
{
System.out.println("hi me");
return "index";
}
}


MvcConfiguration.java

@Configuration
public class MvcConfiguration
extends WebMvcConfigurerAdapter
{
@Bean
public ViewResolver getViewResolver()
{
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".html");
return resolver;
}
}


以及以下目录结构:

src └── main     ├── java     │   └── com     │       └── myangularapp     │           ├── Application.java     │           ├── config     │           │   └── MvcConfiguration.java     │           └── controllers     │               └── BaseController.java     └── webapp         └── WEB-INF             └── index.html

I then have gradle create the application into a war before deploying on tomcat 8.

However, any time I try and visit the website, I always see this page: enter image description here

And the following stack trace:

2017-07-15 00:01:51.551 ERROR 42496 --- [nio-8090-exec-1] o.a.c.c.C.[.[.[.5.0.[dispatcherServlet]  : Servlet.service() for servlet [dispatcherServlet] threw exception

java.lang.StackOverflowError: null
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) ~[servlet-api.jar:na]
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:594) ~[catalina.jar:8.5.15]
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) ~[servlet-api.jar:na]


最终变成:

at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) ~[servlet-api.jar:na]
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:594) ~[catalina.jar:8.5.15]
at org.springframework.web.util.WebUtils.getSessionId(WebUtils.java:288) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1077) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[catalina.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[catalina.jar:8.5.15]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-websocket.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[catalina.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[catalina.jar:8.5.15]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[catalina.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[catalina.jar:8.5.15]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[catalina.jar:8.5.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[catalina.jar:8.5.15]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]


有人知道我在做什么错吗?

------------------------更新------------------------

在此 answer的背面,我的MvcConfiguration类上没有 @EnableWebMvc。我添加了它,视图已解决,一切都开始工作。

最佳答案

Spring Boot将自动添加位于以下任何目录中的静态Web资源:


  
  / META-INF /资源/
  /资源/
  /静态的/
  /上市/
  


您需要创建一些spring想要的目录,创建一个src/main/resources/index.html

问候,

关于java - Java Spring Boot:Servlet [dispatcherServlet]的Servlet.service()抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45112873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com