Java: Accessing properties file inside a war

后端 未结 6 1473
花落未央
花落未央 2020-12-06 06:29

I already searched StackOverflow for \"properties inside war\", but none of the results worked for my case.

I am using Eclipse Galileo and GlassFish v3 to develop a

6条回答
  •  时光说笑
    2020-12-06 07:06

    Since you are using Spring, then use the Resource support in Spring to inject the properties files directly.

    see http://static.springsource.org/spring/docs/3.0.x/reference/resources.html

    Even if the class that requires the properties file is not Spring managed, you can still get access to the ApplicationContext and use it to load the resource

    resource would be something like, classpath:settings.properties, presuming that your properties file got picked up by your build and dropped in the war file.

    You can also inject directly, from the docs:

    
    

提交回复
热议问题