问题
I'm trying to parse @Context UriInfo
to another thread and do some task. But when i try to run it, it gives the error as
Exception in thread "Thread-691" org.jboss.resteasy.spi.LoggableFailure: Unable to find contextual data of type: javax.ws.rs.core.UriInfo
My code as follows
@GET
@Path("/thread")
public void thread(@Context UriInfo url){
Runnable run = new Runnable() {
@Override
public void run() {
System.out.println(">>>>>>>>>>>> " + url.getRequestUri().getQuery());
}
};
Thread t = new Thread(run);
t.start();
}
How can I get the UriInfo to the new thread?
回答1:
Just make the UriInfo parameter final and you will be able to access it from your run() method.
public void thread(@Context final UriInfo url){
I've no idea what you are actually trying to achieve here though. I doubt you actually want to do this.
来源:https://stackoverflow.com/questions/42649287/parsing-context-uriinfo-to-java-thread