Spring的依赖注入的2种方式(1天时间)
今天花了一天的时间才调试出来
private 接口 实现类的那个bean;
最后面的那个名字不能随便的写,必须是配置文件中,实现类的那个bean
就是后面的那个名字写错了,花了整整一天
必须有这句注解扫描才能扫描到注解
进行注解的配置,不需要get方法和set方法,小龙儿说xml文件配置才需要set方法
- package com.baobaotao1;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class CarServiceImpl implements CarService {
- private CarDao carDao;
- public void setCarDao(CarDao carDao) {
- this.carDao = carDao;
- }
- public void produceDi(){
- carDao.produceLun();
- System.out.println("閹绘劒绶垫惔鏇犳磸缂佹瑨婧呯�涳拷");
- }
- public static void main(String[] args){
- System.out.println(123);
- ApplicationContext ctx =
- new ClassPathXmlApplicationContext("applicationContext.xml");
- CarService boss = (CarService) ctx.getBean("carService");
- boss.produceDi();
- }
- }
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?
Spring的依赖注入的2种方式(1天时间)的更多相关文章
- Spring中依赖注入的四种方式
在Spring容器中为一个bean配置依赖注入有三种方式: · 使用属性的setter方法注入 这是最常用的方式: · 使用构造器注入: · 使用Filed注入(用于注解方式). 使用属性的sett ...
- Spring IOC 依赖注入的两种方式XML和注解
依赖注入的原理 依赖注入的方式---XML配置 依赖注入的方式---注解的方式 Spring 它的核心就是IOC和AOP.而IOC中实现Bean注入的实现方式之一就是DI(依赖注入). 一 DI的原理 ...
- Spring注解依赖注入的三种方式的优缺点以及优先选择
当我们在使用依赖注入的时候,通常有三种方式: 1.通过构造器来注入: 2.通过setter方法来注入: 3.通过filed变量来注入: 那么他们有什么区别吗?应该选择哪种方式更好? 三种方式的区别小结 ...
- spring的依赖注入的四种方式,数组与集合注入;引用注入;内部bean注入
三种注入方式 第一种: 基于构造函数 hi.java (bean) package test_one; public class hi { private String name; public hi ...
- 峰Spring4学习(2)依赖注入的几种方式
一.装配一个bean 二.依赖注入的几种方式 com.cy.entity People.java: package com.cy.entity; public class People { pri ...
- ASP.NET MVC中使用Unity进行依赖注入的三种方式
在ASP.NET MVC中使用Unity进行依赖注入的三种方式 2013-12-15 21:07 by 小白哥哥, 146 阅读, 0 评论, 收藏, 编辑 在ASP.NET MVC4中,为了在解开C ...
- SSH深度历险记(八) 剖析SSH核心原则+Spring依赖注入的三种方式
于java发育.一类程序猿必须依靠类的其他方法,它是通常new依赖类的方法,然后调用类的实例,这样的发展问题new良好的班统一管理的例子.spring提出了依赖注入的思想,即依赖类不由程 ...
- SSH深度历险(八) 剖析SSH核心原理+Spring依赖注入的三种方式
在java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依 ...
- Spring:DI依赖注入的几种方式
据我所学,spring实现依赖注入(DI)的方式分为三大类:基于构造器(构造方法)的依赖注入.基于setter的依赖注入.其他方式(c命名空间.p命名空间等).其中推荐使用setter方法注入,这种注 ...
随机推荐
- Linux Centos关机命令
centos关机命令: 1.halt 立马关机 2.shutdown -h 10 1分钟后自动关机 3.poweroff 立刻关机,并且电源也会断掉 4.shutdown -h now 立刻关机(ro ...
- Jdbc连接Oracle12C集群环境
jdbc.url=jdbc:Oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.31.0. ...
- day15 装饰器
关于函数的装饰器 1 .装饰器,(难点,重点) 开闭原则: 对功能的扩展开放 对代码的修改是封闭 通用装饰器语法: def wrapper(fn): def inner(*args,**kwargs) ...
- node(3)Buffer缓冲区
buffer 专门用来存放二进制数据的缓冲区:处理文件流 TCP流 const buf = Buffer.from('runoob', 'ascii'); // 创建一个长度为 10.且用 0x1 填 ...
- Linux系统下yum源配置(Centos 6)
1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载新的CentOS-Base ...
- 对弈的Python学习笔记
#主要序列类型 str list tuple #列表 list ls=[1,2,3,4]#末尾追加ls.append(5) #添加多个,扩展ls.extend([5,6,7]) #在某个位置插入一个值 ...
- DevExpress v18.1新版亮点——Office File API篇
用户界面套包DevExpress v18.1日前正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress Office File API v18.1 的新功能,快来下载试 ...
- ssm使用双数据源
工作中需要接入其他公司业务系统的数据进行分析,于是接入它们的db. 使用双数据源配置感觉如下: database.sessionFactory.扫描器.事务管理器等双份. 听说如果两个数据源需要一起使 ...
- org.quartz-scheduler 动态添加自动任务
1.添加pom.xml <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId> ...
- 九、编写led驱动
led.c #include <linux/init.h> #include <linux/module.h> #include <linux/cdev.h> #i ...