Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading file from tomcat, outside servelet.

 
Ranban Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working on a tomcat application, in which there is a Spring bean which is declared like

<bean name="PleskXMLInputs" class="<FULLY_QUALIFIED_CLASS_NAME>"
depends-on="registered_shared_ServiceLayersCache">
<property name="slCacheIdentifier" ref="..."/>
</bean>

The xml files containing the declarations are declares included in the web.xml, as follows:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring_context.xml
</param-value>
</context-param>

Now the above mentioned bean is used somewhere in the web application. The class does not extend servlet, so I can't use the getServletContext() approach. Is there any way I can read a properties file placed somewhere inside the web application (WEB-INF,WEB-INF/classes, META-INF - anywhere is fine) from inside the bean class?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17987
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WEB-INF/classes is part of the classpath of the webapp. So any resources placed there can be loaded the same way they would be in a stand-alone Java application, via the classpath resource loader.
 
abani patra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
You can use the following code snippet in the xml file to use properties files:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic