Este es el ERROR
Error creating bean with name 'contactService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire method: public void
aqui las clases
Código:
type Informe de Excepción mensaje descripción El servidor encontró un error interno () que hizo que no pudiera rellenar este requerimiento. excepción javax.servlet.ServletException: Servlet.init() para servlet extjs-crud-grid-spring-hibernate lanzó excepción org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) java.lang.Thread.run(Thread.java:619) causa raíz org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.orsisperu.service.ContactService.setContactDao(com.orsisperu.dao.ContactDAO); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.orsisperu.dao.ContactDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) javax.servlet.GenericServlet.init(GenericServlet.java:212) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) java.lang.Thread.run(Thread.java:619)
La interfaz
Código:
package com.orsisperu.dao; import java.util.List; import com.orsisperu.model.Contact; public interface IContactDAO { List<Contact> getContacts(); void deleteContact(String id); Contact saveContact(Contact contacto); }
el dao
Código:
package com.orsisperu.dao; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import com.orsisperu.model.Contact; @Repository public class ContactDAO implements IContactDAO { private HibernateTemplate hibernateTemplate; @Autowired public void setSessionFactory(SessionFactory sessionFactory){ hibernateTemplate=new HibernateTemplate(sessionFactory); } @SuppressWarnings("unchecked") //para evitar error compilacion con java.io.serializable @Override @Transactional(readOnly=true) public List<Contact> getContacts() { // TODO Auto-generated method stub return hibernateTemplate.find("from Contact"); } @Override @Transactional public void deleteContact(String id) { // TODO Auto-generated method stub Object record=hibernateTemplate.load(Contact.class, id); hibernateTemplate.delete(record); } //retorna contacto que fue insertado en la bd @Override @Transactional public Contact saveContact(Contact contacto) { // TODO Auto-generated method stub hibernateTemplate.saveOrUpdate(contacto); return contacto; } }
mi capa servicio
Código:
package com.orsisperu.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.orsisperu.dao.ContactDAO; import com.orsisperu.model.Contact; @Service public class ContactService { @Autowired private ContactDAO contactDao; public void setContactDao(ContactDAO contactDao) { this.contactDao = contactDao; } public List<Contact> getContactList(){ return contactDao.getContacts(); } public Contact createContact(Contact contacto){ return contactDao.saveContact(contacto); } public Contact updateContact(Contact contacto){ return contactDao.saveContact(contacto); } public void deleteContact(String id){ contactDao.deleteContact(id); } }
y mi capa controllador
Aqui parece que sta el erro al tratar de inyectar el bean servicio
Código:
package com.orsisperu.web; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import sun.font.CreatedFontTracker; import com.orsisperu.service.ContactService; @Controller public class ContactController { private ContactService contactService; @Autowired public void setContactService(ContactService contactService) { this.contactService = contactService; } @RequestMapping(value="/contact/view.action") public String view(ModelMap model){ model.addAttribute("listaContact",contactService.getContactList()); return "contact/listaContact"; } }
este es mi archivo spring configuracion
Código:
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- Scans the classpath of this application for @Components to deploy as beans --> <context:component-scan base-package="com.orsisperu" /> <!-- Configures the @Controller programming model --> <mvc:annotation-driven /> <!-- misc --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="suffix" value=".jsp"/> </bean> <!-- Configures Hibernate - Database Config --> <import resource="db-config.xml" /> </beans>
Ojala me puedan dar la mano no se a que se deba
Saludos