spring在开发中起到管理bean的作用,不管是web应用还是应用软件开发。
注入有多种方式,其中注解注入最为受欢迎。(java api 在1.6版本以上才引入关键的注解类如:@Resource)

配置文件xml

<?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-2.5.xsd
http://www.springframework.org/schema/context
http://
www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config/> <bean id="person" class="com.test.spring.bean.person">
<property name="name" value="xxx"/>
<property name="sex" value="男"/>
<property name="addr" value="广州"/>
</bean>
<bean id="jianli" class="com.test.spring.bean.jianli">
<property name="wenping" value="博士"/>
</bean>
</beans>

注意红色部分配置,缺一都用不了注解注入

spring注解注入的学习的更多相关文章

  1. 使用Spring注解注入属性

    本文介绍了使用Spring注解注入属性的方法.使用注解以前,注入属性通过类以及配置文件来实现.现在,注入属性可以通过引入@Autowired注解,或者@Resource,@Qualifier,@Pos ...

  2. spring注解注入:<context:component-scan>以及其中的context:include-filter>和 <context:exclude-filter>的是干什么的?

    转自:https://www.cnblogs.com/vanl/p/5733655.html spring注解注入:<context:component-scan>使用说明   sprin ...

  3. spring注解注入:<context:component-scan>使用说明

    spring从2.5版本开始支持注解注入,注解注入可以省去很多的xml配置工作.由于注解是写入java代码中的,所以注解注入会失去一定的灵活性,我们要根据需要来选择是否启用注解注入. 在XML中配置了 ...

  4. spring注解注入:<context:component-scan>详解

    spring从2.5版本开始支持注解注入,注解注入可以省去很多的xml配置工作.由于注解是写入java代码中的,所以注解注入会失去一定的灵活性,我们要根据需要来选择是否启用注解注入. 我们首先看一个注 ...

  5. spring注解注入properties配置文件

    早期,如果需要通过spring读取properties文件中的配置信息,都需要在XML文件中配置文件读取方式. 基于XML的读取方式: <bean class="org.springf ...

  6. Spring 注解注入—@Qualifier 注释

    当创建多个具有相同类型的 bean 时,并且想要用一个属性只为它们其中的一个进行装配,在这种情况下,你可以使用 @Qualifier 注释和 @Autowired 注释通过指定哪一个真正的 bean ...

  7. Spring中注入bean学习的总结

    1.在类上直接加注解@Component,那么这个类就直接注入到Spring容器中了  ,像@Contrloller,@Service这些本质上都是@Component, 2.@Configurati ...

  8. JAVA框架 Spring 注解注入

    一.首先需要引入jar包:spring-aop-4.2.4.RELEASE.jar.(在spring解压包libs内). 二.如果注解方式注入依赖的对象,需要引用新的约束. 内的:xsd-config ...

  9. spring 注解注入bean

    通过注解方式注入bean,需要在配置类下注入bean 第一步,配置扫描文件夹 首先要在spring.xml中配置需要扫描的配置类 <context:componenet-scan base-pa ...

随机推荐

  1. Cannot change version of project facet Dynamic Web Module to 3.0 异常问题处理

    如何解决Tomcat服务器在初始化应用的时候的以下异常问题 1,Cannot change version of project facet Dynamic Web Module to 3.0 2,O ...

  2. D - Football (aka Soccer)

    Football the most popular sport in the world (americans insist to call it "Soccer", but we ...

  3. vscode 设置 cmder为终端

    "terminal.integrated.shell.windows": "cmd.exe", "terminal.integrated.shellA ...

  4. Mongodb----整理

    ----------------------------------------------------------------------------------mongodb基本操作------- ...

  5. Glufster挂载失败Mount failed. Please check the log file for more details解决办法

    设置两台glusterfs服务器主机名分别为gfs1,gfs2 设置好glusterfs挂载不成功提示如下 Mount failed. Please check the log file for mo ...

  6. poj2728 Desert King【最优比率生成树】【Prim】【0/1分数规划】

    含[最小生成树Prim]模板. Prim复杂度为$O(n^2),适用于稠密图,特别是完全图的最小生成树的求解.   Desert King Time Limit: 3000MS   Memory Li ...

  7. python 同时运行两个程序

    linux的话: python py1.py & python py2/py &

  8. MySQL命令:增删与改

    首先是对数据库的修改: --删除一个叫bbb111的数据库 DROP DATABASE bbb111; 对某数据库里一个表的修改: 重命名一张表 -- 三种效果一样的形式 RENAME TABLE 原 ...

  9. display style edit

    https://html.spec.whatwg.org/multipage/interaction.html#attr-contenteditable <!doctype html> & ...

  10. [daily][mirror][daemonlogger][tc] 我想把一个网卡(port A)的流量,镜像到虚拟机的一个网卡(port VA)上去

    iptables tee 模块 https://blog.gnuers.org/?p=740 http://blog.csdn.net/wesleyflagon/article/details/385 ...