In my spring webservice I'm trying to get the url of my application like "http://localhost:8080/mycontext". My service does not contain any HttpServletRequest var, so I can I get it ?
You can get the current request via the RequestContextHolder like:
ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequest req = sra.getRequest();
req.getContextPath();
req.getPathInfo();
Or you can just inject it via Spring into your service:
private @Autowired HttpServletRequest request;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With