Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring3新手-无此定义例外-我错过了什么?_Spring_Autowired_Spring 3 - Fatal编程技术网

Spring3新手-无此定义例外-我错过了什么?

Spring3新手-无此定义例外-我错过了什么?,spring,autowired,spring-3,Spring,Autowired,Spring 3,刚开始看Spring3和MVC。我得到以下例外 org.springframework.beans.factory.BeanCreationException:创建名为“registerController”的bean时出错:自动关联依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动关联字段:private brownePoints.dao.UserDao brownePoints.web.Regi

刚开始看Spring3和MVC。我得到以下例外

org.springframework.beans.factory.BeanCreationException:创建名为“registerController”的bean时出错:自动关联依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动关联字段:private brownePoints.dao.UserDao brownePoints.web.RegisterController.UserDao;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到依赖项类型为[BrownePoints.dao.UserDao]的匹配bean:至少需要1个符合此依赖项autowire候选项条件的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;
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>


谢谢。

在黑暗中拍摄;组件扫描指令中缺少
UserDaoImpl
包:

<context:component-scan base-package="x.z"/>

在黑暗中拍摄;组件扫描指令中缺少
UserDaoImpl
包:

<context:component-scan base-package="x.z"/>


我们需要查看您的XML配置,并知道这些类在哪些包中。我们需要查看您的XML配置,并知道这些类在哪些包中。好球!!我把我的基本软件包从x.z改成了x,现在它可以接收所有东西了。好球!!我把我的基本包从x.z改成了x,现在它可以接收所有东西。