@Resource example
来源:互联网 发布:监控端口号 编辑:程序博客网 时间:2024/05/19 22:52
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd"><context:annotation-config/><bean id="sexWomenList" class="com.vf.sample.SexWomenLister" ></bean><bean id="womenFinder" class="com.vf.sample.WomenFinder"><constructor-arg type="java.lang.String" value="Yan chen"></constructor-arg><constructor-arg type="int" value="19"></constructor-arg></bean><bean id="a" class="com.vf.sample.WomenFinder"><constructor-arg type="java.lang.String" value="Jia Yu"></constructor-arg><constructor-arg type="int" value="20"></constructor-arg></bean></beans>
package com.vf.sample;public class WomenFinder {/** * @param args */private String name;private int age;private final static String DEFAULT_NAME = "Maggie Q";private final static int DEFAULT_AGE = 18;public WomenFinder() {System.out.println("Copy that.I know how to find the correct women.");name = DEFAULT_NAME;age = DEFAULT_AGE;}public WomenFinder(String name,int age) {this.name = name;this.age = age;}@Overridepublic String toString() {return "Name: " + name + "\nAge: " + age;}}
package com.vf.sample;import javax.annotation.Resource;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;public class SexWomenLister {/** * @param args */private WomenFinder womenFinder;@Resource(name="a")public void setWomenFinder( WomenFinder womenFinder) {this.womenFinder = womenFinder;}public void print() {System.out.println(womenFinder.toString());}}
package com.vf.sample;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext apcx = (ApplicationContext) new ClassPathXmlApplicationContext("beans.xml");
SexWomenLister list = apcx.getBean("sexWomenList",SexWomenLister.class);
list.print();
}
}
Name: Jia Yu
Age: 20
- @Resource example
- AngularJS $resource RESTful example
- [转]Spring Resource loader with GetResource() example
- Struts 2 – Resource bundle example
- Spring Resource bundle with ResourceBundleMessageSource example
- 不看死不瞑目的文档 :Solaris container - Resource Pools Example
- Spring JTA multiple resource transactions in Tomcat with Atomikos example
- Spring JTA multiple resource transactions in Tomcat with Atomikos example
- example
- example
- Example
- example
- Example
- Example
- Example
- Example
- example
- Example
- JavaScript 组合模式
- Compile the Python interpreter statically
- 字符集和字符编码(Charset & Encoding)
- 双击程序没反应的解决办法之一
- iOS开发 应用启动速度的优化
- @Resource example
- Uva 11235 频繁出现的数值(RMQ-Sparse Table 算法)(训练指南)
- Fedora Linux的一些常用设置和常用命令
- HSM层次状态机实战
- Magento CMS分页功能实现
- [URAL-1001 PYTHON SOLUTION]
- wine: No such file or directory
- DIY冰箱
- MYSQL-- 事务处理