自动装配:按照类型来找

会在xml中找类型一样的,

比如 setMessage(SetName setName)上面有@Autowired,会到xml中找<bean id="setname" class="com.yibai.SetName">

package com.yibai;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
public class HelloWorld {
SetName setName;
@Autowired
public void setMessage(SetName setName){
this.setName=setName;
System.out.println("setmessage");
setName.getSetName() ;
}
}
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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">
<context:annotation-config/>
<bean id="helloWorld" class="com.yibai.HelloWorld">
</bean>
<bean id="setname" class="com.yibai.SetName">
</bean>
</beans>

spring IOC 注解@Autowired的更多相关文章

  1. spring IOC注解方式详解

    本文分为三个部分:概述.使用注解进行属性注入.使用注解进行Bean的自动定义. 一,概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以 ...

  2. spring IOC注解与xml配置

    转载自:https://blog.csdn.net/u014292162/article/details/52277756 IOC 1小案例 将对象的依赖交给配置文件来配置(配置文件的名字是可以任意的 ...

  3. Spring通过注解@Autowired/@Resource获取bean实例时为什么可以直接获取接口而不是注入的类

    问: 这个问题困扰了我好久,一直疑问这个接口的bean是怎么注入进去的?因为只看到使用@Service注入了实现类serviceImpl,使用时怎么却获取的接口,而且还能调用到实现类的方法,难道这个接 ...

  4. spring自动注解Autowired配置

    1.spring注解:http://blog.csdn.net/xyh820/article/details/7303330/ 2.最简ssm配置:http://blog.csdn.net/qq_18 ...

  5. spring ioc 注解配置

    要注意spring 版本与jdk的兼容性 applicationContext-resource.xml: <beans xmlns="http://www.springframewo ...

  6. spring IOC 注解@Required

    @Required注解适用于bean属性的setter方法,使用@Required的方法必须在xml中填充,负责报错 例如下面的例子中,student中的setAge和setName有@Require ...

  7. spring IOC 注解@Resource

    1.@Resource(重要)a)加入 :j2ee/common-annotations.jar b)默认按名称,名称找不到,按类型 默认按照名称setName1到xml中找和id相同的,没有的话再找 ...

  8. Spring _day02_IoC注解开发入门

    1.Spring IoC注解开发入门 1.1 注解开发案例: 创建项目所需要的jar,四个基本的包(beans core context expression ),以及两个日志记录的包,还要AOP的包 ...

  9. Spring IoC @Autowired 注解详解

    前言 本系列全部基于 Spring 5.2.2.BUILD-SNAPSHOT 版本.因为 Spring 整个体系太过于庞大,所以只会进行关键部分的源码解析. 我们平时使用 Spring 时,想要 依赖 ...

随机推荐

  1. openCV图像形态学

    #include <cv.h> #include <highgui.h> #include <stdio.h> //平滑处理 int main() { IplIma ...

  2. 解决PL/SQL Developer过期

    1 2 3 4 5 6 分步阅读 PL/SQL Developer过期了,又没有注册码,又不想花钱买,而且事情又非常急,这时候怎么办?不要着急,请随小编一起解决这种情况吧. 工具/原料   PL/SQ ...

  3. Convex combination

    en.wikipedia.org/wiki/Convex_combination 凸组合 In convex geometry, a convex combination is a linear co ...

  4. js滚动到指定位置显示或隐藏元素

    $(function(){ $(window).scroll(function(){ var scroll_top=$(window).scrollTop(); console.log(scroll_ ...

  5. LeetCode:汇总区间【228】

    LeetCode:汇总区间[228] 题目描述 给定一个无重复元素的有序整数数组,返回数组区间范围的汇总. 示例 1: 输入: [0,1,2,4,5,7] 输出: ["0->2&quo ...

  6. HDU - 2709 Sumsets 【递推】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2709 题意 给出一个数N 要求有多少种方式 求和 能够等于N 加的数 必须是 2的幂次 思路 首先可以 ...

  7. Python 案例一(计算人体体脂率)

    #计算人体体脂率 #输入部分 #身高 personHeight = input("请输入你的身高(m):") personHeight = float(personHeight) ...

  8. EntityFramework 学习 一 枚举

    1. Convert an existing property to Enum: using (var ctx = new SchoolDBEntities()) { Teacher tchr = n ...

  9. stdcall、cdecl详解(以及WINAPI和CALLBACK之类的宏对应什么)

    转自:http://blog.csdn.net/huanjieshuijing/article/details/5822942 对_stdcall 的理解在C语言中,假设我们有这样的一个函数:int ...

  10. JS高阶函数的理解(函数作为参数传递)

    JS高阶函数的理解 高阶函数是指至少满足下列条件之一的函数. · 函数可以作为参数被传递 · 函数可以作为返回值输出 一个例子,我们想在页面中创建100个div节点,这是一种写法.我们发现并不是所有用 ...