When i work in spring mcv, attending requests with a controller or service, i can get the root of the my app followin this sample
@Autowired
private HttpServletRequest request;
//in method
String contextPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); //maybe
But when I try to use a scheduled task, I get the null request, it does not exist in this context, since there is no a request from the browser
@Autowired
private HttpServletRequest request;
@Scheduled(cron = "10 14 12 * * *")
public void doSome() {
System.out.println("some");
String contextPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); // error HERE
There is another way, to get the root?