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
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
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Spring
java.lang.InstantiationException
shawn peter
Ranch Hand
Posts: 1325
1
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
in my spring example animal is abstract class.dos is concrete class.
here is my 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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="animal" class="com.my.animal" abstract="true"> <property name="animal" value="father" /> </bean> <bean id="dog" parent="animal"> <property name="dog" value="child" /> </bean> </beans>
here is the main class.
package com.my; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource; public class myApp { public static void main(String[] args) { BeanFactory factory =new XmlBeanFactory(new FileSystemResource("bean.xml")); dog greetingService =(dog) factory.getBean("dog"); } } /[code] here is the error [code] Jun 20, 2009 10:41:12 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from file [C:\hibernatetutorial\Spring\bean.xml] Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dog' defined in file [C:\hibernatetutorial\Spring\bean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.my.animal]: Is it an abstract class?; nested exception is java.lang.InstantiationException Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.my.animal]: Is it an abstract class?; nested exception is java.lang.InstantiationException Caused by: java.lang.InstantiationException at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:85) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:756) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:721) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:384) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at com.my.myApp.main(myApp.java:12)
i cant understand why it gives error when i am going to instatiate a dog class.
shawn peter
Ranch Hand
Posts: 1325
1
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
here is my animal class
package com.my; public abstract class animal { String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } }
here is my dog class
package com.my; public class dog extends animal { private String dog; public String getDog() { return dog; } public void setDog(String dog) { this.dog = dog; } }
Vikas Kapoor
Ranch Hand
Posts: 1374
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
check you bean definition for 'dog'. The error is apparent.
shawn peter
Ranch Hand
Posts: 1325
1
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
what is that mena? what is mean by apparent
shawn peter
Ranch Hand
Posts: 1325
1
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
no, i need to extend's abstract animal class and make dog concrete class.but what is the erroe.dog class is not abstract.
Vikas Kapoor
Ranch Hand
Posts: 1374
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You don't have 'class' attribute for you 'dog' bean definition in bean.xml?
shawn peter
Ranch Hand
Posts: 1325
1
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks Vishal Pandya.I nedd to get abstract clas method and nedd to practise inheritance working on spring.
Vikas Kapoor
Ranch Hand
Posts: 1374
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You're Welcome Aruna.
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
AOP logging throws exception
Unable to configure Spring with Hibernate
Spring+Hibernate can't create SessionFactory bean
jibx binding Error: Nonstatic field name not found in
Problem in spring mvc configuration
More...