因为现在有一需求,在接口中写方法获取 ip,port appname,根据以往情况看只有request对象才有这能力,但是一般只有继承与servlet的类中才能获取这个对象,在网上查了,
@Autowired(required=true)
private HttpServletRequest request;
这可以获取request,但是在调用此接口对应的方法是,出现了异常,
Caused by: 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.
之后继续查,发现好像是因为spring的对象都是单例,再次注入就出现了这个问题,那么问题又回到了怎么获取request对象,或者有什么其他的方法获取访问项目的地址呢?