Can I configure Spring in such a way that I add a property, “isHttps” to the request, and this property can be accessed from anywhere in the code, e.g. a bean class:
public class MyItem{
public String getImageUrl(){
if (isHttps){
//return https url
}
//return http url;
}
}
I can do this using ThreadLocal, but I would like to avoid taking that route.
Another alternative:
You can get the current request as follows:
This uses thread-local under the covers.
If you are using Spring MVC that’s all you need. If you are not using Spring MVC then you will need to register a RequestContextListener or RequestContextFilter in your
web.xml.