Java 未找到线程绑定请求
使用apachecxf依赖项Java 未找到线程绑定请求,java,spring,jetty,jax-rs,cxf,Java,Spring,Jetty,Jax Rs,Cxf,使用apachecxf依赖项CXF-rt-transports-http-jetty-3.1.4.jar测试JAXRS服务。下面是Junit注释- @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations = {"classpath:test-spring-context.xml"}) web.xml(不要认为web.xml是由@WebAppConfiguration
CXF-rt-transports-http-jetty-3.1.4.jar
测试JAXRS服务。下面是Junit注释-
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:test-spring-context.xml"})
web.xml(不要认为web.xml是由@WebAppConfiguration
加载的,但它位于标准目录src/main/webapp/web-INF/web.xml中)
任何帮助都将不胜感激 通过JAX-RS ContainerRequestFilter注入的HttpServletRequest
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.request.ServletRequestAttributes;
@Provider
public class RequestFilter implements ContainerRequestFilter {
private static final String REQUEST_ATTRIBUTES_ATTRIBUTE =
RequestFilter.class.getName() + ".REQUEST_ATTRIBUTES";
@Context private HttpServletRequest httpRequest;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
ServletRequestAttributes attributes = new ServletRequestAttributes(httpRequest);
httpRequest.setAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE, attributes);
LocaleContextHolder.setLocale(httpRequest.getLocale());
RequestContextHolder.setRequestAttributes(attributes);
}
}
src/main/webapp/web.xml不是标准位置。把它放在src/main/webapp/WEB-INF/WEB.xml中。也许这就是它没有注意到您将RequestContextListener声明为侦听器的原因。我错误地在post中放置了错误的路径。它仅位于src/main/webapp/WEB-INF内部。我现在已经更新了这个问题。你能提供一些更深入的见解吗?到底是什么帮助了你,你修复了什么?
<httpj:engine-factory bus="cxf" id="port9191">
<httpj:engine port="9191">
<httpj:threadingParameters minThreads="5"
maxThreads="15" />
<httpj:handlers>
<bean class="org.eclipse.jetty.server.handler.DefaultHandler" />
</httpj:handlers>
<httpj:sessionSupport>true</httpj:sessionSupport>
</httpj:engine>
</httpj:engine-factory>
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils.currentRequestAttributes(WebApplicationContextUtils.java:309) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils.access$400(WebApplicationContextUtils.java:64) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:325) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:320) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:307) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.request.ServletRequestAttributes;
@Provider
public class RequestFilter implements ContainerRequestFilter {
private static final String REQUEST_ATTRIBUTES_ATTRIBUTE =
RequestFilter.class.getName() + ".REQUEST_ATTRIBUTES";
@Context private HttpServletRequest httpRequest;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
ServletRequestAttributes attributes = new ServletRequestAttributes(httpRequest);
httpRequest.setAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE, attributes);
LocaleContextHolder.setLocale(httpRequest.getLocale());
RequestContextHolder.setRequestAttributes(attributes);
}
}