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方法注入,这种注 ...
随机推荐
- [leetcode整理]
=======简单 leetcode164 Maximum Gap sort两次 =======有参考 330 Patching Array 98 Validate Binary Search Tre ...
- Linux如何产看系统信息
如何查看已安装的CentOS版本信息: 1)[root@localhost ~]# cat /proc/version Linux version 2.6.18-194.el5 (mockbuild@ ...
- 10.Python-第三方库requests详解(二)
Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...
- uiautomator2 获取APP Toast内容
前言:appium必须是1.6以上的版本 环境(安装和安装都可以运行成功,我也不确定要不要这个): 1.抓到toast需要安装uiautomator2,安装npm:npm install -g cnp ...
- Ubuntu下teamviewer的安装
安装i386库 1.sudo apt-get install libc6:i386 libgcc1:i386 libasound2:i386 libexpat1:i386 libfontconfig1 ...
- Python 基础关于编码
一.编码的种类: 1 acsic码 基本不用 不同编码之间互用会产生乱码, 2unicode A 字母 4个字节 00000000 00000000 00100100 01000 ...
- iOS 获取当前正在显示的ViewController
//获取当前屏幕显示的viewcontroller - (UIViewController *)getCurrentVC { UIViewController *result = nil; UIWin ...
- 7-log4j2之自定义Appender
一.添加Maven依赖 <dependencies> <dependency> <groupId>org.apache.logging.log4j</grou ...
- springsecurity基于数据库验证用户
之前的springsecurity程序都是将数据存放在内存中的,通过 <security:user-service> <security:user name="user&q ...
- 【转】Delphi XE10 Android Splash设备自适应和沉浸式状态条
再次提笔写博客,已经相隔7年,原来的CSDN账号需要手机验证,而我的手机又捆绑到这个账号了,就用新账号吧,不想折腾了. 原账号的帖子,有研究DICOM3.0的可以看下:http://blog.csdn ...