gpt4 book ai didi

java - Jersey 和 Springboot 应用程序抛出 java.lang.StackOverflowError

转载 作者:行者123 更新时间:2023-12-01 16:45:13 25 4
gpt4 key购买 nike

尝试使用 Jersey 创建 Spring-boot 应用程序来响应 REST 调用。代码类似于这个question 。应用程序成功启动,但当 REST 调用时,如日志中所示,存在无限循环,并且在一段时间后引发异常。

appContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan
base-package="org.ideoholic" />
<context:annotation-config />
<!-- <mvc:annotation-driven /> -->
</beans>

Java配置代码:

@Configuration
@Import({ WebXmlConfiguration.class })
@ImportResource({ "classpath*:appContext.xml" })
@EnableAutoConfiguration
public class ApplicationConfiguration {

}


@Configuration
@Profile("basicauth")
public class WebXmlConfiguration {

@Bean
public Filter springSecurityFilterChain() {
return new DelegatingFilterProxy();
}

@Bean
public ServletRegistrationBean<Servlet> jersey() {
Servlet jerseyServlet = new SpringServlet();
ServletRegistrationBean<Servlet> jerseyServletRegistration = new ServletRegistrationBean<Servlet>();

jerseyServletRegistration.setServlet(jerseyServlet);
jerseyServletRegistration.addUrlMappings("/rest/v1/*");
jerseyServletRegistration.setName("jersey-servlet");
jerseyServletRegistration.setLoadOnStartup(1);
jerseyServletRegistration.addInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
jerseyServletRegistration.addInitParameter("com.sun.jersey.config.feature.DisableWADL", "true");
jerseyServletRegistration.addInitParameter("com.sun.jersey.config.property.packages", "org.ideoholic");
return jerseyServletRegistration;
}

}


@SpringBootApplication
public class RestSpringApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(RestSpringApplication.class);
}

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

日志中看到的错误是无限循环 DelegatingFilterProxy

ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Filter execution threw an exception] with root cause
java.lang.StackOverflowError: null
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)

完整的代码可以在 Github 上找到。

最佳答案

删除springSecurityFilterChain(),如果您需要添加过滤器,请使用@WebFilter

Annotation used to declare a servlet filter.

关于java - Jersey 和 Springboot 应用程序抛出 java.lang.StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61793461/

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