1

I am using Spring MVC in my application, generally the configuration like the beans, services, daos are configed either by xml or java.

However there are some configuration which not belong to any beans such as the application name, application version and etc, and I want to save them to an standalone file, but I do need to use these kinds of properties in the other beans or the jsp pages.

Of cource I can create a bean named AppConfig, and inject the properties to the bean through the xml, and inject the AppConfig to any beans which need them, but there are two problems:

1 I have to add the AppConfig dependency for the related beans.

2 Once the property is required in the page, I have to expose the AppConfig to the controller.

So I wonder if there is any alternative solution?

hguser
  • 35,079
  • 54
  • 159
  • 293
  • Look at this - http://stackoverflow.com/questions/3933862/how-to-use-property-from-property-file-specified-in-propertyplaceholderconfigure - it should help. – Ashley Frieze Apr 28 '15 at 08:09

1 Answers1

0

Write a Properties file with name config.properties. Then write application name, application version and etc. in that. Then add below line and now you can access those values directly in your Controller.

@PropertySource("classpath:config.properties")
Shayan Ghosh
  • 882
  • 6
  • 14