今天花了一天的时间才调试出来

private      接口   实现类的那个bean;

最后面的那个名字不能随便的写,必须是配置文件中,实现类的那个bean

就是后面的那个名字写错了,花了整整一天


必须有这句注解扫描才能扫描到注解


进行注解的配置,不需要get方法和set方法,小龙儿说xml文件配置才需要set方法


  1. package com.baobaotao1;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.support.ClassPathXmlApplicationContext;
  5.  
  6. public class CarServiceImpl implements CarService {
  7.  
  8. private CarDao carDao;
  9. public void setCarDao(CarDao carDao) {
  10. this.carDao = carDao;
  11.    }

  12. public void produceDi(){
  13. carDao.produceLun();
  14. System.out.println("閹绘劒绶垫惔鏇犳磸缂佹瑨婧呯�涳拷");
  15. }
  16.  
  17. public static void main(String[] args){
  18. System.out.println(123);
  19. ApplicationContext ctx =
  20. new ClassPathXmlApplicationContext("applicationContext.xml");
  21. CarService boss = (CarService) ctx.getBean("carService");
  22. boss.produceDi();
  23. }
  24. }

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carTest' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'carService' while setting bean property 'carService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carService' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'carDao' of bean class [com.baobaotao1.CarServiceImpl]: Bean property 'carDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

  1.  
  1.  


Spring的依赖注入的2种方式(1天时间)的更多相关文章

  1. Spring中依赖注入的四种方式

    在Spring容器中为一个bean配置依赖注入有三种方式: · 使用属性的setter方法注入  这是最常用的方式: · 使用构造器注入: · 使用Filed注入(用于注解方式). 使用属性的sett ...

  2. Spring IOC 依赖注入的两种方式XML和注解

    依赖注入的原理 依赖注入的方式---XML配置 依赖注入的方式---注解的方式 Spring 它的核心就是IOC和AOP.而IOC中实现Bean注入的实现方式之一就是DI(依赖注入). 一 DI的原理 ...

  3. Spring注解依赖注入的三种方式的优缺点以及优先选择

    当我们在使用依赖注入的时候,通常有三种方式: 1.通过构造器来注入: 2.通过setter方法来注入: 3.通过filed变量来注入: 那么他们有什么区别吗?应该选择哪种方式更好? 三种方式的区别小结 ...

  4. spring的依赖注入的四种方式,数组与集合注入;引用注入;内部bean注入

    三种注入方式 第一种: 基于构造函数 hi.java (bean) package test_one; public class hi { private String name; public hi ...

  5. 峰Spring4学习(2)依赖注入的几种方式

    一.装配一个bean 二.依赖注入的几种方式 com.cy.entity   People.java: package com.cy.entity; public class People { pri ...

  6. ASP.NET MVC中使用Unity进行依赖注入的三种方式

    在ASP.NET MVC中使用Unity进行依赖注入的三种方式 2013-12-15 21:07 by 小白哥哥, 146 阅读, 0 评论, 收藏, 编辑 在ASP.NET MVC4中,为了在解开C ...

  7. SSH深度历险记(八) 剖析SSH核心原则+Spring依赖注入的三种方式

           于java发育.一类程序猿必须依靠类的其他方法,它是通常new依赖类的方法,然后调用类的实例,这样的发展问题new良好的班统一管理的例子.spring提出了依赖注入的思想,即依赖类不由程 ...

  8. SSH深度历险(八) 剖析SSH核心原理+Spring依赖注入的三种方式

           在java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依 ...

  9. Spring:DI依赖注入的几种方式

    据我所学,spring实现依赖注入(DI)的方式分为三大类:基于构造器(构造方法)的依赖注入.基于setter的依赖注入.其他方式(c命名空间.p命名空间等).其中推荐使用setter方法注入,这种注 ...

随机推荐

  1. Linux Centos关机命令

    centos关机命令: 1.halt 立马关机 2.shutdown -h 10 1分钟后自动关机 3.poweroff 立刻关机,并且电源也会断掉 4.shutdown -h now 立刻关机(ro ...

  2. Jdbc连接Oracle12C集群环境

    jdbc.url=jdbc:Oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.31.0. ...

  3. day15 装饰器

    关于函数的装饰器 1 .装饰器,(难点,重点) 开闭原则: 对功能的扩展开放 对代码的修改是封闭 通用装饰器语法: def wrapper(fn): def inner(*args,**kwargs) ...

  4. node(3)Buffer缓冲区

    buffer 专门用来存放二进制数据的缓冲区:处理文件流 TCP流 const buf = Buffer.from('runoob', 'ascii'); // 创建一个长度为 10.且用 0x1 填 ...

  5. Linux系统下yum源配置(Centos 6)

    1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载新的CentOS-Base ...

  6. 对弈的Python学习笔记

    #主要序列类型 str list tuple #列表 list ls=[1,2,3,4]#末尾追加ls.append(5) #添加多个,扩展ls.extend([5,6,7]) #在某个位置插入一个值 ...

  7. DevExpress v18.1新版亮点——Office File API篇

    用户界面套包DevExpress v18.1日前正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress Office File API v18.1 的新功能,快来下载试 ...

  8. ssm使用双数据源

    工作中需要接入其他公司业务系统的数据进行分析,于是接入它们的db. 使用双数据源配置感觉如下: database.sessionFactory.扫描器.事务管理器等双份. 听说如果两个数据源需要一起使 ...

  9. org.quartz-scheduler 动态添加自动任务

    1.添加pom.xml <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId> ...

  10. 九、编写led驱动

    led.c #include <linux/init.h> #include <linux/module.h> #include <linux/cdev.h> #i ...