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
Ron McLeod
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Rob Spoor
Junilu Lacar
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Piet Souris
Carey Brown
Bartenders:
Forum:
Spring
Spring Autowire - java.lang.NoSuchMethodException
Muhammad Abdul Arif
Greenhorn
Posts: 28
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi All,
I was trying to use annotations in my project which was using SimpleFormControllers. I am stuck in adding @Autowired to one of my DAO class. Below is the code. Can you guys please help me how to autowire this DAO.
public interface GenericDao <T, PK extends Serializable> { /** Retrieve an object that was previously persisted to the database using * the indicated id as primary key */ public T findbyId(PK id); /** Save or Update changes made to a persistent object. */ void saveOrUpdate(T transientObject); /** Remove an object from persistent storage in the database */ void delete(T persistentObject); }
@Component @Transactional public class GenericDaoHibernateImpl <T, PK extends Serializable> implements GenericDao<T, PK> { private Class<T> type; @Autowired private HibernateTemplate hibernateTemplate; @Autowired private JdbcTemplate jdbcTemplate; public GenericDaoHibernateImpl(Class<T> type) { this.type = type; } ......
@Component public class MemberDAO extends GenericDaoHibernateImpl<Member, String> { public MemberDAO(Class<Member> type) { super(type); } }
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberDAO' defined in file [F:\Arif\Eclipse Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\InfySwift\WEB-INF\classes\com\infyswift\entities\member\dao\MemberDAO.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.infyswift.entities.member.dao.MemberDAO]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.infyswift.entities.member.dao.MemberDAO.<init>() at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) 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:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474) ... 43 more Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.infyswift.entities.member.dao.MemberDAO]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.infyswift.entities.member.dao.MemberDAO.<init>() at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:70) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958) ... 54 more Caused by: java.lang.NoSuchMethodException: com.infyswift.entities.member.dao.MemberDAO.<init>() at java.lang.Class.getConstructor0(Class.java:2706) at java.lang.Class.getDeclaredConstructor(Class.java:1985) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:65) ... 55 more
Mark Spritzler
ranger
Posts: 17347
11
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yep very simple. your
@Component
public class MemberDAO
Doesn't have a no args constructor, and there is no @Autowired on any of its constructor(s).
Mark
Perfect World Programming, LLC
-
iOS Apps
How to Ask Questions the Smart Way FAQ
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
java.lang.InstantiationException
Error while instantiating JdbcTemplate in spring-config.xml?
Unable to configure Spring with Hibernate
java.lang.VerifyError,runtime exception,can anyone explain when or why get this runtime exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name...
More...