Wednesday, April 1, 2009

Resources and Spring

Spring provides an easy way to store resources. For instance you need to use an xslt transformation file in your class.

1. Add resource member in your class
public class A {
private myResource;
public void setMyResource( myResource) {
this.myResource = myResource;
// You Code
// Now you can get the file/stream from the resource:
// myResource.getFile();
// myResource.getInputStream();

2. Define the resource in spring configuration

<bean id="myBean" class="A">
<property name="myResource">
<value type="">{path}</value>

The {path} could be:
- /WEB-INF/...
- classpath:/...
- file:/c:/...

No comments:

Post a Comment