Results 1 to 1 of 1

Thread: Loading classpath resources and setting file path in Bean

  1. #1
    Join Date
    Jun 2012
    Posts
    7

    Default Loading classpath resources and setting file path in Bean

    I have an integration test that needs to get the file path of a properties file in the project and inject it into a bean. The location of the properties file is /src/test/resources/foo.properties in the project and I need someway in the application context to inject it like this:

    Code:
    <bean id="config" class="com.foo.rest.data.Config">
         <property name="fileLocation" value="file location of internal project resource" />
    </bean>
    If anyone can help it would be much appreciated. Thanks.

    Solved it.

    Code:
    <bean id="classLoader" class="java.security.SecureClassLoader" />
    <bean id="config" class="com.foo.rest.data.Config">
            <property name="fileLocation" value="#{classLoader.getResource('foo.properties').getPath()}" />
    </bean>
    Last edited by ColinMc; Jan 7th, 2013 at 12:01 PM. Reason: Solved the problem

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •