剛開始看春3和MVC。我得到以下異常...Spring 3新手 - NoSuchBeanDefinitionException - 我錯過了什麼?
org.springframework.beans.factory.BeanCreationException:創建名爲'registerController'的bean時出錯:注入自動裝配依賴項失敗;嵌套異常是org.springframework.beans.factory.BeanCreationException:無法自動裝入字段:private browniePoints.dao.UserDao browniePoints.web.RegisterController.userDao;嵌套異常是org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到匹配依賴類型爲[browniePoints.dao.UserDao]的bean類型:期望至少有1個bean符合此依賴關係的自動連線候選。依賴註釋:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
從所有的例子我有谷歌這是所有需要的。我錯過了什麼?
接口...
package browniePoints.dao;
public interface UserDao
{
實現...
package browniePoints.dao.impl;
@Component
public class UserDaoImpl implements UserDao
{
@Autowired
private DataSource dataSource;
控制器...
package browniePoints.web;
@Controller
public class RegisterController
{
@Autowired
private UserDao userDao;
web.xml中有一個servlet,它指向以下xml配置...
<?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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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">
<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="browniePoints.web" />
<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />
<!-- Forwards requests to the "/" resource to the "index" view -->
<mvc:view-controller path="/" view-name="index"/>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- point URLs ending .jsp to views in /WEB-INF/views -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"> </property>
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- load properties from config.properites -->
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="config.properties" />
</bean>
<!-- Define a SQL Server datasource -->
<bean id="dataSource" destroy-method="close" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>
謝謝。
我們需要看到你的XML配置,並且知道這包這些類是 – skaffman 2011-05-12 17:05:46