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

  • Home
  • SEARCH
  • 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 8712511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:07:29+00:00 2026-06-13T05:07:29+00:00

I am trying to make my first bean in Spring but got a problem

  • 0

I am trying to make my first bean in Spring but got a problem with loading a context.
I have a configuration XML file of the bean in src/main/resources.

I receive the following IOException:

Exception in thread “main” org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [src/main/resources/beans.xml]; nested exception is

java.io.FileNotFoundException: class path resource [src/main/resources/beans.xml] cannot
be opened because it does not exist

but I don’t get it, since I do the following code test:

File f = new File("src/main/resources/beans.xml");
System.out.println("Exist test: " + f.exists());

which gives me true! resources is in the classpath. What’s wrong?

  • 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-06-13T05:07:30+00:00Added an answer on June 13, 2026 at 5:07 am

    Thanks, but that was not the solution. I found it out why it wasn’t working for me.

    Since I’d done a declaration:

    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    

    I thought I would refer to root directory of the project when beans.xml file was there.
    Then I put the configuration file to src/main/resources and changed initialization to:

    ApplicationContext context = new ClassPathXmlApplicationContext("src/main/resources/beans.xml");
    

    it still was an IO Exception.

    Then the file was left in src/main/resources/ but I changed declaration to:

    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    

    and it solved the problem – maybe it will be helpful for someone.

    Edit:

    Since I get many people thumbs up for the solution and had had first experience with Spring as student few years ago, I feel desire to explain shortly why it works.

    When the project is being compiled and packaged, all the files and subdirs from ‘src/main/java’ in the project goes to the root directory of the packaged jar (the artifact we want to create). The same rule applies to ‘src/main/resources’.

    This is a convention respected by many tools like maven or sbt in process of building project (note: as a default configuration!). When code (from the post) was in running mode, it couldn’t find nothing like "src/main/resources/beans.xml" due to the fact, that beans.xml was in the root of jar (copied to /beans.xml in created jar/ear/war).

    When using ClassPathXmlApplicationContext, the proper location declaration for beans xml definitions, in this case, was "/beans.xml", since this is path where it belongs in jar and later on in classpath.

    It can be verified by unpacking a jar with an archiver (i.e. rar) and see its content with the directories structure.

    I would recommend reading articles about classpath as supplementary.

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

Sidebar

Related Questions

I am trying to make my first public .net website but I have a
I'm trying to make this 2-player web game application using Spring MVC. I have
I'm pretty much a newb with spring-hibernate and I have been trying to make
I'm trying to make my first game, a console tetris. I have a class
First I have to make clear what i am Trying to accomplish, it's going
I am trying to compile with make. I have source in two directories, src
I'm trying to make my first chrome extension here.It's a sticky note board. But
I'm trying to make the following form in JSF 2.0 but a have some
I'm trying to make my first jQuery slider, and I have this code: $(#str).keyup(function(event)
Im trying to make my first app with eclipse and phonegap. But when I

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.