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 6011267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:14:08+00:00 2026-05-23T02:14:08+00:00

I am trying to use ClassPathXmlApplicationContext in my java standalone code to load applicationContext.xml

  • 0

I am trying to use ClassPathXmlApplicationContext in my java standalone code to load applicationContext.xml that is inside a jar file which is in my class path.

ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:**/applicationContext*.xml");

applicationContext.xml entry as follows,

 <bean id="myAdder" class="com.foo.bar.MyAdder">
        <property name="floatAdder" ref="floatAdder"/>        
    </bean>

And, when I try to load a bean that way I am getting NoSuchBeanException. Can’t a bean by loaded in this way?

The jar file is added to my classpath as a maven dependency. When I see the Java Build Path in Eclipse for this project, I see this jar linked as M2_REPO/…/..

I was assuming I can load the bean inside the jar file as the jar is in classpath this way. Am I missing something?

Thanks,Abi

  • 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-23T02:14:09+00:00Added an answer on May 23, 2026 at 2:14 am

    This should work, I just created the 2 projects and checked.

    Project A (standard Maven project created with STS) has applicationContext.xml in src/main/resources.

    pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.D</groupId>
    <artifactId>A</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    
    <properties>        
        <spring.version>3.0.5.RELEASE</spring.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>
    </project>
    

    applicationContext.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <bean id="myAdder" class="com.foo.bar.MyAdder">
        <property name="foo" value="bar" />
    </bean>
    
    </beans>
    

    Project B:

    pom.xml: same as A, except A is added as dependency:

    <dependency>
       <groupId>org.D</groupId>
       <artifactId>A</artifactId>
       <version>0.0.1-SNAPSHOT</version>
    </dependency>
    

    Start.java in project B:

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "classpath*:**/applicationContext*.xml");
    
        MyAdder myAdder = (MyAdder) context.getBean("myAdder");
        System.out.println(myAdder.getFoo());
    }
    

    mvn install A first, then run Start in project B.

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

Sidebar

Related Questions

Trying to use an excpetion class which could provide location reference for XML parsing,
I'm trying to use jQuery to format code blocks, specifically to add a <pre>
I'm trying to use the Optiflag package in my Ruby code and whenever I
I am trying use the jQuery table sorter plugin for a table that is
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying use a Java Uploader in a ROR app (for its ease
I'm trying use jquery to remove a class from an element (not knowing ahead
i'm trying use webview to load a image from sdcard i use this path
I have a regex that I'm trying use to validate against strings. Trying to
I have a 3rd party DLL that I am trying to use in a

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.