自动装配:按照类型来找

会在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. TRansportation ANalysis and SIMulation System

    https://www.fhwa.dot.gov/planning/tmip/transims/background.cfm?from=groupmessage

  2. springboot错误页面处理

    springboot作为微服务的便捷框架,在错误页面处理上也有了一些新的处理,不同于之前的pringmvc500的页面处理是比较简单的,用java config或者xml的形式,定义如下的Bean即可 ...

  3. You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

    [root@localhost dreamstart]# composer installLoading composer repositories with package informationI ...

  4. Power Designer体验之旅

    版权声明:本文为博主原创文章.未经博主允许不得转载. https://blog.csdn.net/wang13667539325/article/details/36025245 从某种程度上说.不论 ...

  5. C#泛型命名潜规则

    public class List<T>{} public class LinkedList<T>{} public class SortedList<TKey,TVal ...

  6. linux 中sort命令 按照指定列排序

    sort怎样按指定的列排序0000 27189 41925425065f 15 419254250663 7 419254250675 5 419254250691 76 419254250693 2 ...

  7. 1django 视图与网址

    创建一个项目,名字叫mysite django-admin startproject mysite(项目名) 成功后,看到如下样式 mysite ├── manage.py └── mysite ├─ ...

  8. 【leetcode刷题笔记】Convert Sorted List to Binary Search Tree

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  9. BZOJ 2058 [Usaco2010 Nov]Cow Photographs:逆序对【环上最小逆序对】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2058 题意: 给你一个由1~n组成的排列,首尾相接围成一个环. 你可以任意次交换其中两个相 ...

  10. name lookup of 'res' changed for new ISO 'res' scoping

    #include<iostream> using namespace std; int pow ( int val, int exp ); int main() { int val = 2 ...