Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide
this week in the
Programmer Certification
forum!
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:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Spring
Spring:xception in thread "main" org.springframework.beans.factory.BeanCreationException
Kaustubh G Sharma
Ranch Hand
Posts: 1283
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Getting below exception while running mentioned spring
test
code : please help
Exception
Mar 13, 2013 5:26:53 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from file [C:\DI_spring\config\beanEx.xml] Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employee' defined in file [C:\DI_spring\config\beanEx.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at com.nihilent.TestClass.main(TestClass.java:12)
TestClass.java
package com.nihilent; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource; public class TestClass { public static void main(String ss[]) { BeanFactory factory = new XmlBeanFactory(new FileSystemResource("C:/DI_spring/config/beanEx.xml")); Employee emp = (Employee) factory.getBean("employee"); emp.testM1(); } }
Employee.java
package com.nihilent; public class Employee { private String name; private int age; private Address address; public Employee() { //super(); } public Employee(Address address) { //super(); this.address = address; } public Employee(String name, int age, Address address) { //super(); this.name = name; this.age = age; this.address = address; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public void testM1(){ address.testM(); } }
BeanEx.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" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id ="address" class="com.nihilent.Address" > </bean> <bean id ="employee" class="com.nihilent.Employee" autowire="constructor" > <constructor-arg index="0" value="22" /> <constructor-arg index="1" value="kaustubh" /> </bean> </beans>
Address.java
package com.nihilent; public class Address { private String line1; public String getLine1() { return line1; } public void setLine1(String line1) { this.line1 = line1; } public void testM(){ System.out.println("testing auto wiring...."); } }
No Kaustubh No Fun, Know Kaustubh Know Fun..
Bill Gorder
Bartender
Posts: 1682
7
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
<bean id ="employee" class="com.nihilent.Employee" autowire="constructor" > <constructor-arg index="0" value="22" /> <constructor-arg index="1" value="kaustubh" />
That does not match any of the constructors you have defined for you employee object.
You need to either provide no arguments, an Address bean, or a
String
, int, Address
[
How To Ask Questions
][
Read before you PM me
]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
spring form submission
Spring AOP HELP needed
Spring+Hibernate can't create SessionFactory bean
Problem in spring mvc configuration
Spring 2.5 - Transaction example
More...