Spring-MVC - Error creating bean with name 'productsController': Injection of autowired dependencies failed -
im having problem spring-mvc project. @autowiring not creating beans required. ive worked on over 4 days , followed search results. nothing has worked. can please take look. thank you
the error stack this:
org.springframework.beans.factory.beancreationexception: error creating bean name 'productscontroller': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private com.davis.ty.service.productsservice com.davis.ty.controller.productscontroller.productsservice; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.davis.ty.service.productsservice] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)} org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:292)
my servlet.xml is:
<?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" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- dispatcherservlet context: defines servlet's request-processing infrastructure --> <context:annotation-config /> <context:component-scan base-package="com.davis.ty" /> <!-- handles http requests /resources/** efficiently serving static resources in ${webapproot}/resources directory --> <mvc:resources mapping="/resources/**" location="/resources/" /> <!-- resolves views selected rendering @controllers .jsp resources in /web-inf/views directory --> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/views/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="propertyconfigurer" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer" p:location="/web-inf/jdbc.properties" /> <bean id="messagesource" class="org.springframework.context.support.reloadableresourcebundlemessagesource"> <property name="basename" value="classpath:messages" /> <property name="defaultencoding" value="utf-8" /> </bean> <bean id="datasource" class="org.apache.commons.dbcp2.basicdatasource" destroy-method="close" p:driverclassname="${jdbc.driverclassname}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> <bean id="sessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="configlocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="configurationclass"> <value>org.hibernate.cfg.annotationconfiguration</value> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <tx:annotation-driven /> <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> </bean> </beans>
my controller is:
package com.davis.ty.controller; import java.util.map; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.validation.bindingresult; import org.springframework.web.bind.annotation.modelattribute; import org.springframework.web.bind.annotation.pathvariable; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import com.davis.ty.domain.products; import com.davis.ty.service.productsservice; @controller public class productscontroller { @autowired private productsservice productsservice; @requestmapping(value = "/index", method = requestmethod.get) public string listproducts (map<string, object> map) { system.out.println("index"); map.put("products", new products()); map.put("productslist", productsservice.listproducts()); return "index"; } @requestmapping(value = "/add", method = requestmethod.post) public string addproducts(@modelattribute("products") products products, bindingresult result) { productsservice.addproducts(products); return "redirect:/index"; } @requestmapping("/delete/{id}") public string deleteproducts(@pathvariable("id") integer id) { productsservice.removeproducts(id); return "redirect:/index"; } }
my service program is:
package com.davis.ty.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.davis.ty.dao.productsdao; import com.davis.ty.domain.products; @service public class productsserviceimpl { @autowired private productsdao productsdao; @transactional public void addproducts(products products){ productsdao.addproduct(products); } @transactional public list<products> listproducts() { return productsdao.listproducts(); } @transactional public void removeproducts(integer id) { productsdao.removeproducts(id); } }
well, productsserviceimpl
class doesn't implement productsservice
... there's no way bean injected in field of type productsservice
.
Comments
Post a Comment