自动装配:按照类型来找

会在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. ubuntu编译内核模块报错:Required key not available 的解决

    系统为ubuntu18.04, 在编译内核模块insmod helloworld.ko的时候提示如下错误. 出现此问题的原因是,Ubuntu Kernel 使用 EFI_SECURE_BOOT_SIG ...

  2. Symfony 使用KnpTimeBundle

    使用time_diff时出现:diff.ago.hour; 解决:1:引入"knplabs/knp-time-bundle": "^1.7",https://g ...

  3. eclipse svn 分支合并到主干

    最近公司产品上线,整个系统架构包含有七八个子系统,并且子系统都是集群部署.所以每次升级维护都要确保尽可能不出问题.因为整个系统刚上线不久,意味着新系统不定期有BUG需修复,但新功能模块也在持续的开发中 ...

  4. 基于卡方的独立性检验原理及R语言实现

    在读到<R语言实战>(第二版)P143页有关卡方独立性检验所记 假设检验 假设检验(Test of Hypothesis)又称为显著性检验(Test of Ststistical Sign ...

  5. 【leetcode刷题笔记】Evaluate Reverse Polish Notation

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  6. vRA7.x services do not register after a restart (2147446)

    After restarting the vRealize Automation Appliance, you experience these symptoms: In the vRealize A ...

  7. 操作系统原理2——OS结构

    操作系统原理2——OS结构   计算机系统是由硬件系统和软件系统两部分组成, 操作系统是软件系统的一个组成部分,它是直接在硬件系统的基础上工作的,所以在研究操作系统之前,先必须对计算机系统的结构有一个 ...

  8. MySQL 高可用架构在业务层面的应用分析

    MySQL 高可用架构在业务层面的应用分析 http://mp.weixin.qq.com/s?__biz=MzAxNjAzMTQyMA==&mid=208312443&idx=1&a ...

  9. QuickReport FastReport

    一.QuickReport1.安装Component->Install packages->X:/Program Files/Borland/Delphi7/Bin/dclqrt70.bp ...

  10. maven 3.2.5 的安装及简单示例

    http://www.mvnrepository.com 一直没有使用maven,它的作用就不说了,这二天需要用到,发现网上都是以前的版本,所以,我一边配置,一边记录. 一 下载maven 现在很多I ...