Spring自定义@Qualifier

来源:互联网 发布:java常用设计模式详解 编辑:程序博客网 时间:2024/06/03 11:26

Spring可以自定义@Qualifier

参考链接 http://yangchengwanhong.blog.sohu.com/234465733.html

例子代码如下:

import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import javax.inject.Qualifier;@Target({ElementType.FIELD,ElementType.PARAMETER,ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Qualifierpublic @interface StringedInstrument {}

使用的时候在需要被注解的类上面加上,即可

@StringedInstrumentpublic class Guitar extends Instrument {}
public class Instrument {private String name;private String sound;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSound() {return sound;}public void setSound(String sound) {this.sound = sound;}}



0 0
原创粉丝点击