• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why am I getting NoSuchBeanDefinition Exception? I am new to Spring!

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i appreciate any help, I am so tired of being stuck on this today!

I have a Spring context file called testing.xml which contains this bean (proprietary names are changed for privacy):

<bean id="Foo" class="com.abc.testing.xyz.bear.zoo.SomeClass">
<property name="customerEmail" value="testemail@foo.com"/>
</bean>

Then in my class:

com.abc.testing.xyz.bear.zoo;

public class Foo {

private String customerEmail = null;

public void init() {
context = new ClassPathXmlApplicationContext("testing.xml");
customerEmail = (String) ctx.getBean("Foo");
}

And I am getting the exception. Why can't it find it? It does find the beans in the testing.xml file.

Thank you.

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure there's not another "testing.xml" somewhere else in your classpath. Try to rename the file to see what happens.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see a few issues.

1) Where is your setter method for that property.
2) You are casting the getBean return value to a String, when the Bean type is not a String but a com.abc.testing.xyz.bear.zoo.SomeClass
3) What is this init method? What is the purpose of the object that is the bean is also the code to lookup itself from the ApplicationContext?

I am assuming this is just a test for you to try out Spring.

I recommend making the simple SomeClass with the String property and getter and setter of it.

Then create another class that has a public static void main(String[] args) and in that method create the ApplicationContext and get the Bean.

Also, make sure your testing.xml is in the root of your classpath.

Good Luck

Mark
 
Jane Foster
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help. I made the changes you suggested and I was stumped because it was like my changes were being ignored. I finally remembered that the context file is getting copied over to the bin folder in my ant build script. I ran the build and it worked great. Thanks again
 
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic