Was wondering if someone can help me with an 'Injection of autowired dependencies failed':
INFO: Initializing Spring FrameworkServlet 'spring'
In ViewDVDController()
Oct 26, 2011 11:50:07 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'viewDVDController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationEapp structure.jpgxception: Could not autowire field: private springmvc.application.inventory.impl.InventoryMana gerImpl springmvc.presentation.ViewDVDController.manager; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [springmvc.application.inventory.impl.InventoryMana gerImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Aut owired(required=true)}
InventoryManagerImpl class:
ViewDVDController:Code:package springmvc.application.inventory.impl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.core.support.JdbcDaoSupport; import springmvc.application.inventory.DVDDetails; import springmvc.application.inventory.DVDInfo; import springmvc.application.inventory.InvalidDvdIdException; import springmvc.application.inventory.InventoryManager; public class InventoryManagerImpl extends JdbcDaoSupport implements InventoryManager { @Override public void addDvd(DVDDetails details) throws InvalidDvdIdException { // TODO Auto-generated method stub } @Override public DVDDetails getDetails(String dvdID) { // TODO Auto-generated method stub return null; } @Override public List<DVDInfo> getAll() { String sql = "SELECT DVD_TITLE_ID, TITLE FROM dvdtitle"; final List<DVDInfo> result = new ArrayList<DVDInfo>(); //obtain JdbcTemplate JdbcTemplate template = getJdbcTemplate(); //Execute sql statemtn using RowCallbackHandler template.query(sql, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { DVDInfo info = populate(rs); result.add(info); } } ); return Collections.unmodifiableList(result); } private DVDInfo populate(ResultSet rs) throws SQLException { DVDInfo info = new DVDInfo(); info.setID(rs.getString("DVD_TITLE_ID")); info.setTitle(rs.getString("TITLE")); return info; } }
web.xml:Code:package springmvc.presentation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; //import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.multiaction.MultiActionController; //import springmvc.application.inventory.DVDDetails; import springmvc.application.inventory.DVDInfo; import springmvc.application.inventory.InventoryManager; import springmvc.application.inventory.impl.InventoryManagerImpl; //import javax.servlet.http.HttpServletRequest; //import javax.servlet.http.HttpServletResponse; import java.util.List; @Controller public class ViewDVDController extends MultiActionController { public ViewDVDController() { System.out.println("In ViewDVDController()"); } @Autowired // ? private InventoryManager manager; public InventoryManager getManager() { return manager; } public void setManager(InventoryManager manager) { this.manager = manager; } @RequestMapping (value="viewAll.view", method=RequestMethod.GET) public ModelAndView viewAll() throws Exception { System.out.println("In ViewDVDController.viewAll()"); List<DVDInfo> all = manager.getAll(); return new ModelAndView("ListAll", "catalog", all); } }
spring.properties:Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>SpringMVCExample</display-name> <!-- todo Declare the DispatcherServlet. Beware of the name! Another file will tell you what name to use! --> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/inventory/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
spring-servlet:Code:app.jdbc.driverClassName=org.apache.derby.jdbc.ClientDriver app.jdbc.url=jdbc:derby://localhost:1527/springclass app.jdbc.username=sa app.jdbc.password=password
Code:<?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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" 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-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="springmvc" /> <bean id="viewResolver" class= "org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/views/inventory/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
jdbc-context.xml:
applicationContext.xml:Code:<?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.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:property-placeholder location="/WEB-INF/spring.properties" /> <!-- Enable annotation style of managing transactions --> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" > <property name="driverClass" value="${app.jdbc_driverClass}"/> <property name="jdbcUrl" value="${app.jdbc_url}"/> <property name="user" value="${app.jdbc_username}"/> <property name="password" value="${app.jdbc_password}"/> <property name="acquireIncrement" value="5"/> <property name="idleConnectionTestPeriod" value="60"/> <property name="maxPoolSize" value="100"/> <property name="maxStatements" value="50"/> <property name="minPoolSize" value="10"/> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property name="dataSource-ref" ref="dataSource" /> </bean> </beans>
app structure.jpgCode:<?xml version="1.0" encoding="UTF-8"?> <import resource="jdbc-context.xml" />


Reply With Quote