1

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?).

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.

nrad0
  • 43
  • 7
  • The first option should work, it looks so good :) – Roman C Aug 09 '17 at 17:27
  • Hi @RomanC , just to clarify, you think that the best option is to use spring-mvc? Puting bullet points in the question with 1,2 for what I tried and 1,2 for possible solutions was not very smart. I edited the numeration in the question – nrad0 Aug 10 '17 at 09:52
  • You saying was not very smart? Why? It should work fine. Actually I didn't get what you talking, what hacks are required? Where the evidence (in the source code) for it? – Roman C Aug 10 '17 at 11:37
  • What I meant was that my question was not very well written but nevermind. The hack that I needed since sitemesh filter is working outside the Spring context was to create an environment filter that I could use for setting environment data for all requests, autowire the bean that I needed to have access too (the properties) in the filter and configure the filter in web.xml, As described in https://stackoverflow.com/a/14160827/6310531 – nrad0 Aug 10 '17 at 15:36
  • Is it solved your problem? – Roman C Aug 10 '17 at 17:15
  • Yes. I just fear that using spring-mvc might be an overkill, and cause additional difficulties in dependency management since I'm already using struts. That is way I created this question in the first place. To have other opinions. – nrad0 Aug 10 '17 at 17:18
  • Your fear is unnecessary, spring mvc works fine with struts2 filter. – Roman C Aug 10 '17 at 17:32
  • Don't access config files in the view. Do it in the controller if you have to. – Aleksandr M Aug 10 '17 at 18:39
  • Hi @AleksandrM, that solution implies that one more Action is called in every request I make, because I want this properties to be available at all my pages. This means the number of requests of my application double. – nrad0 Aug 11 '17 at 09:29
  • Sound like a XY problem. What do you want to achieve? What property do you need in every jsp? – Aleksandr M Aug 11 '17 at 18:19
  • Some javascript configurations for our helpdesk (the helpdesk is available in every page). We use an external library for the helpdesk and if they decide to change something we have to make a new release. What I want to achieve is I want to be able to access some properties in jsp files without repacking the project. – nrad0 Aug 13 '17 at 02:19

0 Answers0