spring IOC 注解@Resource
2024-10-21 15:39:54
1.@Resource(重要)
a)加入 :j2ee/common-annotations.jar
b)默认按名称,名称找不到,按类型
默认按照名称setName1到xml中找和id相同的,没有的话再找和SetName类型一样的
public class HelloWorld {
SetName setName;
@Resource
public void setMessage(SetName setName1){
this.setName=setName1;
System.out.println("setmessage");
setName1.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">
<!-- <property name="message" value="Hello World!"/> -->
</bean>
<bean id="setName1" class="com.yibai.SetName">
</bean>
<bean id="setname12" class="com.yibai.SetName">
</bean>
</beans>
最新文章
- 【代码笔记】iOS-获得现在的日期
- VirtualBox安装MS-DOS6.22(图文教程)
- 识别 Linux上的设备(磁盘)类型
- PHP面向对象讲解
- 关于webapp的一点思考
- Apache+MySQL+PHP开发环境的搭建(一)
- iOS 宏(define)与常量(const)的正确使用
- strstr 函数用法
- RX学习笔记:正则表达式
- mysql学习笔记4---mysql 复制---源代码
- [QT]Qt+VS2012+Win8 64Bit安装
- 普通Java程序员学习使用的6个JDK内建工具
- 字符串(后缀自动机):Codeforces Round #129 (Div. 1) E.Little Elephant and Strings
- Rabbitmq 性能测试
- python写zip破解器
- python语法_str_eval
- CF Manthan, Codefest 16 B. A Trivial Problem
- LeetCode(99):恢复二叉搜索树
- [20171225]没有备份数据文件的恢复.txt
- arguments.callee 和 caller
热门文章
- web 文件下载
- 九度OJ 1193:矩阵转置 (矩阵计算)
- 1.Python学习---helloworld
- 将本地jar包手动复制到Maven库中,在其它电脑上用Maven打包时出错
- [Java面试一]Spring总结以及在面试中的一些问题.(转发:http://www.cnblogs.com/wang-meng/p/5701982.html)
- php......调研投票练习
- 每天一个Linux命令(32)date命令
- DEV开发之汉化
- 【leetcode刷题笔记】Simplify Path
- 第二十一篇 socket