• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException:

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Can anyone please help me out to resolve the above mentioned error that I am getting when I am trying to run one sample springs application?

This is my java file:

package com.Springs;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class Spring1
{
public static void main(String[] args)
{
XmlBeanFactory bean= new XmlBeanFactory(new ClassPathResource("context.xml"));
Inject demo = (Inject) bean.getBean("mybean");
System.out.println(demo);
}
}

class Inject
{
private String name;
private String company;
private String email;
private String address;
private int age;

public void setName(String name)
{
this.name = name;
}

public void setCompany(String company)
{
this.company = company;
}

public void setEmail(String email)
{
this.email = email;
}

public void setAddress(String address)
{
this.address = address;
}

public void setAge(int age)
{
this.age = age;
}

public String toString()
{
return String.format("Name: %s\n" +" Age: %d\n" +" Address: %s\n" +" Company: %s\n" +" E-mail: %s",
this.name, this.age, this.address, this.company,this.email);
}
}


This is my context.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="mybean"
class="Inject"
p:name="Keerthi Kumar"
p:company="Accenture"
p:email="keerthi.k.narayan@accenture.com"
p:address="Bangalore"
p:age="24"/>
</beans>

Awaiting for your valuable reply.

Thanks,
Keerthi Kumar N
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Format you message with bb-code.
2. Show full stack trace.
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can you please let me know how to show the full stack trace and how to format the same with bb-code. Since I am new to springs I am not aware of these things.

Please do the needful.

Thanks,
Keerthi Kumar N
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can figure out how to format your code here. To show the full stack trace, copy all the errors from where you found that one (BeanCreationException), probably from your IDE's console, and post here.
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can please anyone help me out to overcome the below error.

Aug 19, 2009 8:47:26 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [context.xml]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybean' defined in class path resource [context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'company' of bean class [Inject]: No property 'company' found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
at com.Springs.Spring1.main(Spring1.java:11)
Caused by: org.springframework.beans.InvalidPropertyException: Invalid property 'company' of bean class [Inject]: No property 'company' found
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1313)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 8 more
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does Inject class have property company?
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

yeah, I have added the property in the Inject class. The same code has been pasted in my previous posts. Please check the same and help me out in this!

Thanks,
Keerthi Kumar N
 
stanislav bashkirtsev
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hm... Try to add getters for properties..
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I tried adding getters() as well. But still no go

Please help me out !

Thanks,
Keerthi Kumar N
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have getCompany?
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This is my Inject class:

package com.Springs;

class Inject
{


private String name;
private String company;
private String email;
private String address;
private int age;

public void setName(String name)
{
this.name = name;
}

public void setCompany(String company)
{
this.company = company;
}

public void setEmail(String email)
{
this.email = email;
}

public void setAddress(String address)
{
this.address = address;
}

public void setAge(int age)
{
this.age = age;
}

public String getName() {
return name;
}

public String getCompany() {
return company;
}

public String getEmail() {
return email;
}

public String getAddress() {
return address;
}

public int getAge() {
return age;
}

public String toString()
{
return String.format("Name: %s\n" +" Age: %d\n" +" Address: %s\n" +" Company: %s\n" +" E-mail: %s",
this.name, this.age, this.address, this.company,this.email);
}
}
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please check if your spring application is able to locate your context.property file, where you declare your bean definition.
Ensure the file is loaded properly on start up.

Also, check if you have given the fully qualified class name in your bean definition.

Regards,
Srikanth
 
stanislav bashkirtsev
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not normal... Try to create a project from scratch.
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This is my context.xml file.

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="mybean"
class="Inject"
p:name="Keerthi Kumar"
p:company="Accenture"
p:email="keerthi.k.narayan@accenture.com"
p:address="Bangalore"
p:age="24"/>
</beans>

Also I have placed this file in the following path:

D:\MyWorkSpace\SpringDemo1\src\context.xml


Thanks,
Keerthi Kumar N


 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change class="Inject" to class="com.Springs.Inject".
 
Keerthi Kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks a lot for your help It really worked

Thanks,
Keerthi Kumar N
 
I don't always make ads but when I do they're tiny
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic