I want to be able to access some properties in jsp files without repacking the project but I'm not sure what is the most elegant way.
I'm using spring 4.0.9 and struts. I am already using a properties file that can be loaded from an external file via PropertyPlaceHolderConfigurer. The alternatives I tried were:
- Use spring-mvc tag (spring:eval) to get the properties from the *.properties file (via PropertiesFactoryBean). I got it to work but since I'm using struts2 I fear that using spring-mvc might be an overkill, and cause additional difficulties in dependency management (also since I'm using sitemesh an additional 'hack' is needed for this to work, which I found here: How to obtain model attribute or spring's bean in sitemesh decorator?).
- Create a custom struts2 tag and inject the propertie. I found that this is not so simple since the tags are not instantiated by spring but by xxx, and so it's hard to get hold of the properties (or access to the applicationContext, for that matter) within the Tag Object. I followed the answers from here: is there an elegant way to inject a spring managed bean into a java custom/simple tag' with no success.
Now for possible solutions I thought:
- Create a new action to retrieve the properties. However, this means more requests. For example, for a property needed on all pages of the application this means duplicating the requests.
- Create a static pojo with variables for each property, populating all the properties with @Value("{each.property}") at load.
None of this options seems like a good one, so I would like to hear other opinions.