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方法注入,这种注 ...
 
随机推荐
- [HDU1890]RoboticSort
			
Problem 每次找到最小值,然后把它和它前面的数翻转,然后找第二小数······ 然后输出这些数的下标. Solution 用splay维护,每次找到最小值,然后翻转前面区间. Notice 细节 ...
 - 【资料收集】QT学习资料
			
几个专栏 Qt学习之路(3):Hello, world!(续) - 豆子空间 - 51CTO技术博客 http://devbean.blog.51cto.com/448512/194137 Qt 学习 ...
 - :命令模式:Command
			
#ifndef __COMMAND_H__ #define __COMMAND_H__ #include <vector> #include "Equipment.h" ...
 - 牛客国庆集训派对Day5     数论之神
			
题目描述 终于活成了自己讨厌的样子. 这是她们都还没长大的时候发生的故事.那个时候,栗子米也不需要为了所谓的爱情苦恼. 她们可以在夏日的午后,花大把的时间去研究生活中一些琐碎而有趣的事情,比如数论. ...
 - nodejs  .http模块, cheerio模块 实现 小爬虫.
			
代码: var http = require("http"); var cheerio = require("cheerio"); var url = 'htt ...
 - python3自学第二天,模块,三元运算
			
1.模块的认识. sys模块,os模块等 如何引入模块 import os cmd_res1=os.system("dir") # 执行命令dir,不保存结果 print(cmd_ ...
 - 2019-03-18-day013-装饰器与内置函数
			
上周回顾 函数: def 函数名(): 缩进 函数体 闭包: a = 50 def func(): a = 10 def avg(): print(a) 函数名的使用: 当做值被赋值给变量 当做返回值 ...
 - For all entries in
			
Today I read about a blog explaining very detailedly on how to correctly use the key words FOR ALL E ...
 - 启动apache 找不到 mbstring.dll
			
启动appserv时 提示 无法启动此程序 因为计算机中丢失php mbstring.dll 这种原因一般都是组件加载顺序引起的,在php.ini文件里确保 extension=php_mbstr ...
 - JavaScript操作符-3---算数,逻辑,赋值,比较,三元
			
JavaScript操作符 学习目标 1.掌握什么是表达式 2.掌握javascript操作符的分类 3.掌握算数操作符 什么是表达式 将类型的数据(如常量.变量.函数等),用运算符号按一定的规则链接 ...