spring注解注入的学习
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注解注入的学习的更多相关文章
- 使用Spring注解注入属性
本文介绍了使用Spring注解注入属性的方法.使用注解以前,注入属性通过类以及配置文件来实现.现在,注入属性可以通过引入@Autowired注解,或者@Resource,@Qualifier,@Pos ...
- spring注解注入:<context:component-scan>以及其中的context:include-filter>和 <context:exclude-filter>的是干什么的?
转自:https://www.cnblogs.com/vanl/p/5733655.html spring注解注入:<context:component-scan>使用说明 sprin ...
- spring注解注入:<context:component-scan>使用说明
spring从2.5版本开始支持注解注入,注解注入可以省去很多的xml配置工作.由于注解是写入java代码中的,所以注解注入会失去一定的灵活性,我们要根据需要来选择是否启用注解注入. 在XML中配置了 ...
- spring注解注入:<context:component-scan>详解
spring从2.5版本开始支持注解注入,注解注入可以省去很多的xml配置工作.由于注解是写入java代码中的,所以注解注入会失去一定的灵活性,我们要根据需要来选择是否启用注解注入. 我们首先看一个注 ...
- spring注解注入properties配置文件
早期,如果需要通过spring读取properties文件中的配置信息,都需要在XML文件中配置文件读取方式. 基于XML的读取方式: <bean class="org.springf ...
- Spring 注解注入—@Qualifier 注释
当创建多个具有相同类型的 bean 时,并且想要用一个属性只为它们其中的一个进行装配,在这种情况下,你可以使用 @Qualifier 注释和 @Autowired 注释通过指定哪一个真正的 bean ...
- Spring中注入bean学习的总结
1.在类上直接加注解@Component,那么这个类就直接注入到Spring容器中了 ,像@Contrloller,@Service这些本质上都是@Component, 2.@Configurati ...
- JAVA框架 Spring 注解注入
一.首先需要引入jar包:spring-aop-4.2.4.RELEASE.jar.(在spring解压包libs内). 二.如果注解方式注入依赖的对象,需要引用新的约束. 内的:xsd-config ...
- spring 注解注入bean
通过注解方式注入bean,需要在配置类下注入bean 第一步,配置扫描文件夹 首先要在spring.xml中配置需要扫描的配置类 <context:componenet-scan base-pa ...
随机推荐
- J - Romantic
The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees ar ...
- POJ3628:Bookshelf 2【01背包】
Description Farmer John recently bought another bookshelf for the cow library, but the shelf is gett ...
- 思科交换机根据mac地址限制主机
思科交换机可以根据客户端mac地址限制访问 查看对应IP的mac地址及vlan show arp | in 10.1.62.188 进入设置模式 configure terminal mac addr ...
- VC++、Win32 SDK、MFC的区别
这是一个初进行开发人员都可能遇到过的概念不清的问题,自己当年也同样有过误解,做技术我感觉一定要专,但是,不代表毫不关心相关的知识,至少概念层次上要知道,所以,这里还是再把这些内容纪录下来,好记性不如烂 ...
- CentOS 7.4下使用yum安装MySQL5.7.20 最简单的 (引用)
引用 https://blog.csdn.net/z13615480737/article/details/78906598 CentOS7默认数据库是mariadb, 但是 好多用的都是mysql ...
- CentOS7 vsftpd 安装及配置
0x:卸载vsftpd [root@localhost ~]# yum remove vsftpd [root@localhost ~]# find / -name "vsftpd*&quo ...
- Kindle Paper White 使用感受视频上线啦!
大家可以通过以下链接前往我的主页观看视频哦! https://www.youtube.com/watch?v=CESqzxTrAq4&t=322s 欢迎大家点赞.关注! 这期视频用iPhone ...
- {Django基础八之cookie和session}一 会话跟踪 二 cookie 三 django中操作cookie 四 session 五 django中操作session
Django基础八之cookie和session 本节目录 一 会话跟踪 二 cookie 三 django中操作cookie 四 session 五 django中操作session 六 xxx 七 ...
- [No0000177]详解/etc/profile、/etc/bash.bahsrc、~/.profile、~/.bashrc的用途
之前安装Linux的一些软件时,总要修改Linux的配置文件.当时也是一知半解.而且,网上有些安装教程,会说,修改配置文件后要重启Linux.但事实上是不需要重启的. Linux安装时可能要修改的配置 ...
- 自动化运维工具-pssh工具安装配置及简单使用讲解
1.先决条件:安装pssh工具要求python版本大于2.4即可. 安装pssh工具的主机针对远程主机需要配置免秘钥认证: ssh-keygen -t rsa ssh-copy-id [remoteh ...