spring 3 と MVC を見始めたところです。次の例外が発生します...
org.springframework.beans.factory.BeanCreationException: 「registerController」という名前の Bean の作成中にエラーが発生しました: 自動配線された依存関係の注入に失敗しました。ネストされた例外は org.springframework.beans.factory.BeanCreationException: Could not autowire フィールドです: private BrowniePoints.dao.UserDaobrowniePoints.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 には、次の xml 構成を指す 1 つのサーブレットがあります...
<?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>
ありがとう。