Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:51:10+00:00 2026-05-25T05:51:10+00:00

I have a bean that is created by Spring. The actual class resides in

  • 0

I have a bean that is created by Spring. The actual class resides in a different JAR than Spring. This bean is passed a path as a constructor argument. However, I am having difficulty retrieving a handle to the file. The file is in WEB-INF/classes/. I’ve tried relative pathing based on WEB-INF, but obviously that didn’t work.

XML:

 <bean id="configurationManager" class="package.ConfigurationManager" 
      scope="singleton">           
      <property name="configurationMapping">
            <bean class="package.PropertiesFileConfigurationMapper">
                <constructor-arg type="java.lang.String">
                    <value>/path/to/file</value>
                </constructor-arg>
            </bean> 
      </property>                     
</bean> 

Bean:

public class ConfigurationMapper {

    public ConfigurationMapper(String resource) {
            _map = new HashMap<String, String>();
        String property = null;
        BufferedReader reader = null;
        try {
            FileReader file = new FileReader(resourcePath);
            reader = new BufferedReader(file);
            while ((property = reader.readLine()) != null) {
                if (property.matches("(.+)=(.+)")) {
                    String[] temp = property.split("(.+)=(.+)");
                    _map.put(temp[0], temp[1]);
                }
            }
        } catch (Exception ex){
            ex.printStackTrace();
        } finally {
            if (reader != null)
                reader.close();
        }
    }

    //other methods to manipulate settings
}

How can I get the proper path to the rm.properties file and pass it to the bean at runtime?

Edit: Added constructor code.

Edit: I got it. I changed the constructor argument to no longer take a path. It now takes a Resource, so Spring has found the resource that I wanted loaded.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:51:11+00:00Added an answer on May 25, 2026 at 5:51 am

    java.io.File and FileReader only work for actual files. A resource packed inside a JAR file isn’t itself a file.

    The easiest way to load it is as a classpath resource:

    Replace this:

    FileReader file = new FileReader(resourcePath);
    reader = new BufferedReader(file);
    

    with something like this:

    InputStream inputStream = getClass().getResourceAsStream();
    reader = new BufferedReader(new InputStreamReader(inputStream));
    

    Better yet, use Spring’s Resource abstraction, by declaring the constructor parameter as org.springframework.core.io.Resource:

    public ConfigurationMapper(Resource resource) {
       ...
       InputStream inputStream = resource.getInputStream();
       reader = new BufferedReader(new InputStreamReader(inputStream));
    

    When you then supply the path:

    <constructor-arg value="classpath:/path/to/file"/>
    

    Spring will automatically create a ClasspathResource for that path (using a classpath) , and pass it to your constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
I have created a spring bean that contains a list of other beans, like
Is it possible in Spring that a class for bean doesn't have a public
Assuming that I have a CronTriggerBean similar to <bean id=midMonthCronTrigger class=org.springframework.scheduling.quartz.CronTriggerBean> <property name=jobDetail ref=reminderJobDetail
Imagine that i have the following code: <a:repeat value=#{bean.getList()} var=x > <li class=la> <span>
I have a single spring bean similar to the following: public class MyServiceImpl {
I have a spring bean that I have configured in applicationContext like below: <bean
I am using Spring Security 3.0 with JSPs. I have created a RequireVerificationFilter that
I have a MDB (Message driven bean) that receives messages with String which represent
We have some JavaEE5 stateless EJB bean that passes the injected EntityManager to its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.