aspose file tools*
The moose likes Spring and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Exception in thread "main" org.springframework.beans.factory.BeanCreationException:" Watch "Exception in thread "main" org.springframework.beans.factory.BeanCreationException:" New topic
Author

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

Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
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


Cheers,
Keerthi Kumar N
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
1. Format you message with bb-code.
2. Show full stack trace.
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
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
Eduardo Bueno
Ranch Hand

Joined: Jun 04, 2009
Posts: 155
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

Joined: Apr 20, 2009
Posts: 105
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
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Does Inject class have property company?


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
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

Joined: Aug 17, 2009
Posts: 75
Hm... Try to add getters for properties..
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

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

Please help me out !

Thanks,
Keerthi Kumar N
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Do you have getCompany?
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
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);
}
}
Srikanth Visamangalam Thattai
Greenhorn

Joined: Jul 24, 2007
Posts: 3
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


Srikanth
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
It's not normal... Try to create a project from scratch.
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
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

Joined: Jul 05, 2005
Posts: 1936
Change class="Inject" to class="com.Springs.Inject".
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

Thanks a lot for your help It really worked

Thanks,
Keerthi Kumar N
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: