I am pretty sure there is a super-simple solution to this problem, but I have yet to find one.
Here is the situation. I need to construct a call-back URL to pass out with my JSON data. This URL needs to have the correct hostname in it, so if I am running in my Eclipse environment the url woud be http://localhost:8080/some_stuff, but in my Prod environment it would be http://myserver.com/some_stuff.
The most straight-forward solution would be to use the headers, grab the "Host", and plug it in. The problem is I can't over-ride the showJson() method in my controller due to the problem described in this post.
In the meantime, I need a solution today, so I thought: What if I just have some sort of custom properties file and push/pull in the host value from that? I thought this would be simple, but so far it has not been.
The problem is that the controllers are all defined through annotations, and I haven't found a way to "push" a property value in via annotations. What makes it more complicated is that the values of a spring bean are called "properties", so Google finds WAY too much non-related results.
My current attempt has been to "pull" in the value using System.getProperty(), but the PropertyPlaceholderConfigurer I setup doesn't seem to add the properties in the custom properties file to System.properties.
Here is my config for loading the property:
I put app.properties in the "Servers/SpringSource tc Server Developer Edition v2.1-config", which also has the catalina.properties as well as a bunch of other Tomcat-related stuff. I figure its getting loaded since ignoreResourceNotFound defaults to "false" and I am not seeing any errors/warnings. In the Controller method I tried this:Code:<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath*:app.properties</value> </property> </bean>
But host is null after this line.Code:String host = System.getProperty("url.host");
I am sure I am missing something here. Not sure what, thought.