??xml version="1.0" encoding="utf-8" standalone="yes"?>久久夜色精品国产欧美乱极品,亚洲资源在线,国产精品第一第二http://www.aygfsteel.com/FORRogue/category/50924.html我会微笑着面对一切,但是与快乐无养Izh-cnMon, 14 May 2012 18:57:00 GMTMon, 14 May 2012 18:57:00 GMT60JEE6 Weld Extensionhttp://www.aygfsteel.com/FORRogue/archive/2012/03/15/371984.htmlRogueRogueThu, 15 Mar 2012 15:20:00 GMThttp://www.aygfsteel.com/FORRogue/archive/2012/03/15/371984.htmlhttp://www.aygfsteel.com/FORRogue/comments/371984.htmlhttp://www.aygfsteel.com/FORRogue/archive/2012/03/15/371984.html#Feedback0http://www.aygfsteel.com/FORRogue/comments/commentRss/371984.htmlhttp://www.aygfsteel.com/FORRogue/services/trackbacks/371984.htmlWeld Extended 扩展接口     Weld 为我们提供了一个接?Extendsion 来方便我们对Weldq行扩展Q比如来整合工作,整合其他框架技术,或者实C个基于weld新框Ӟ像Seam3.
    
    我们利用 Extension 接口到底能做哪些事?
  • Ҏ入某一个Bean时进行拦截,包括注入前、初始化话这个Bean之前之后、摧毁这个Bean之前
  • 让一个不能注入的BeanQ可以实现注入。(不过基本所有的Bean都是可以注入的)
  • 动态添加、修Ҏ?br />
  • 其他我还不知道的作用

实现一个Extension

    实现一个Extension是通过是对Weld 容器生命周期事gq行监听实现。Weld 中通过 Event + @Oberves 可以实现对一个时间的监听?
    
    Weld 生命周期事gQ?
  • BeforeBeanDiscovery
  • ProcessAnnotatedType
  • ProcessInjectionTarget and ProcessProducer
  • ProcessBean and ProcessObserverMethod
  • AfterBeanDiscovery
  • AfterDeploymentValidation
    首先Q我们需要写一?Extension 的实现类。里面对某一个事件监听就可以了?br />     class MyExtension implements Extension {  }
    然后Q我们需要在META-INF/services 目录下,Z个名?/span>javax.enterprise.inject.spi.Extension 文gQ在q里文g里面写上我们的实现类?br />     org.mydomain.extension.MyExtension
    
    下面l出一个对 CRUDService 接口的注入的监听Q?br />     
public class ExtensionTest implements Extension { 
    void processInjectionTarget(@Observes ProcessInjectionTarget<CURDService> pit) {
        final InjectionTarget<CURDService> it = pit.getInjectionTarget();
        AnnotatedType<CURDService> at = pit.getAnnotatedType();
        System.out.println("processInjectionTarget");
        InjectionTarget<CURDService> wrapped = new InjectionTarget<CURDService>() {
            @Override
            public void inject(CURDService instance, CreationalContext<CURDService> ctx) {
                it.inject(instance, ctx);
                System.out.println("instance inject");               
            }
            @Override
            public void dispose(CURDService x) {
                System.out.println("instance dispose");
                it.dispose(x);
            }
            @Override
            public Set<InjectionPoint> getInjectionPoints() {
                System.out.println("get injectpoints");
                return it.getInjectionPoints();
            }
            @Override
            public CURDService produce(CreationalContext<CURDService> ctx) {
                System.out.println("produce creationalcontext");
                return it.produce(ctx);
            }
            @Override
            public void postConstruct(CURDService x) {
                System.out.println("post instance construct");
                it.postConstruct(x);
            }
            @Override
            public void preDestroy(CURDService x) {
                System.out.println("pre instance destroy");
                it.preDestroy(x);
            }
        };
        pit.setInjectionTarget(wrapped);
    }
}

q样我们可以对注入q个cȝ一些行行拦截。通过ExtensionQ我们可以做很多很多事,实现AOP面向切面Q这栯己可以实现安全机Ӟ在Bean范围开启事务等{?/span>

看好JEE6 CDIQؓJEE6 时代的到来做准备吧。。?/span>



Rogue 2012-03-15 23:20 发表评论
]]>
Java EE6 Weld(1): 上下文、依赖注入和限定?/title><link>http://www.aygfsteel.com/FORRogue/archive/2012/02/23/370600.html</link><dc:creator>Rogue</dc:creator><author>Rogue</author><pubDate>Thu, 23 Feb 2012 15:26:00 GMT</pubDate><guid>http://www.aygfsteel.com/FORRogue/archive/2012/02/23/370600.html</guid><wfw:comment>http://www.aygfsteel.com/FORRogue/comments/370600.html</wfw:comment><comments>http://www.aygfsteel.com/FORRogue/archive/2012/02/23/370600.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/FORRogue/comments/commentRss/370600.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/FORRogue/services/trackbacks/370600.html</trackback:ping><description><![CDATA[<h2><span style="font-size: 14pt; color: #993366; "><strong> 一、Weld?/strong></span></h2>    <span style="font-size: 10pt; font-family: Tahoma; ">Java EE 6.0 的核心:JSR-299规范Q?/span><span style="background-color: #ffffff; color: #333333; line-height: 20px; text-align: left; font-size: 10pt; font-family: Tahoma; ">提供了如下功能:</span><br /><br /><div><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: left; background-color: #ffffff; "><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">        </font><span style="font-size: 13px; line-height: 20px; color: #333333; font-family: Tahoma; ">1. cd安全的依赖注?/span><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">        </font><span style="font-size: 13px; line-height: 20px; color: #333333; font-family: Tahoma; ">2. 注入对象的上下文生存周期理</span><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">        </font><span style="font-size: 13px; line-height: 20px; color: #333333; font-family: Tahoma; ">3. 事g提醒模型</span><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">        </font><span style="font-size: 13px; line-height: 20px; color: #333333; font-family: Tahoma; ">4. l定拦截器通过用户自定义的注解QAnnotationQ?/span><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">        </font><span style="font-size: 13px; line-height: 20px; color: #333333; font-family: Tahoma; ">5. cd安全的装饰器</span><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">        </font><span style="font-size: 13px; line-height: 20px; color: #333333; font-family: Tahoma; ">6. 为整合第三方框架提供了完整的 SPI 支持</span><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">        </font><span style="font-size: 13px; line-height: 20px; color: #333333; font-family: Tahoma; ">7. ?JSFQServlet / JSP q行了整?/span><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">        </font><span style="font-size: 13px; line-height: 20px; color: #333333; font-family: Tahoma; ">8. ?JSF 提供长会话(ConversationQ上下文支持<br /><br /></span><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">    Weld 是一个实C JSR-299 的框架。主要由JBoss完成其实玎ͼ目主页Q?/font><a style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; color: #333333; ">http://www.seamframework.org/Weld</a><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; "> 。最新发布了  Weld 2.0.0.Alpha1 版本?/font><br /><br /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">    Weld 工程的搭建是非常单的, q里介绍一?Weld+JSF ?Tomcat 7.x 中的工程搭徏的方法:</font><br /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">    1Q通过Eclipse 直接建立一?Dynamic Web Project , Runtime 选择 tomcat7 , Servlet 版本选择3.0 ?/font><br /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">    2Q添加所需jar文gQ由?tomcat 是非 jee容器Q所以要加入  weld-servlet.jar ?  q有JSF ? jsf-api.jar  , jsf-imp.jar  ?jstl-1.2.jar </font><br /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; "><span style="font-size: 10pt; ">    3Q在web.xml d监听器来启动weld</span></font><br /><font color="#333333" style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; ">    </font><span style="font-family: Verdana, sans-serif, 宋体; line-height: 20px; background-color: #eeeeee; font-size: 10pt; "><</span><span style="font-family: Verdana, sans-serif, 宋体; line-height: 20px; background-color: #eeeeee; font-size: 10pt; ">listener</span><span style="font-family: Verdana, sans-serif, 宋体; line-height: 20px; background-color: #eeeeee; font-size: 10pt; ">></span></p><div style="font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 20px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; ">      <span style="color: #000000; font-size: 10pt; "><</span><span style="color: #000000; font-size: 10pt; ">listener</span><span style="color: #000000; font-size: 10pt; ">-</span><span style="color: #0000ff; font-size: 10pt; ">class</span><span style="color: #000000; font-size: 10pt; ">></span><span style="color: #000000; font-size: 10pt; ">org.jboss.weld.environment.servlet.Listener</span><span style="color: #000000; font-size: 10pt; "></</span><span style="color: #000000; font-size: 10pt; ">listener</span><span style="color: #000000; font-size: 10pt; ">-</span><span style="color: #0000ff; font-size: 10pt; ">class</span><span style="color: #000000; font-size: 10pt; ">></span><span style="color: #000000; "><br />   </span><span style="color: #000000; font-size: 10pt; "></</span><span style="color: #000000; font-size: 10pt; ">listener</span><span style="color: #000000; font-size: 10pt; ">></span></div><font face="Verdana, sans-serif, 宋体" size="2"><span style="line-height: 20px; font-size: 10pt; ">    4Q在META-INF下,dcontext.xml 为tom</span><span style="line-height: 20px; font-family: Tahoma; font-size: 10pt; ">cat</span></font><span style="color: #333333; line-height: 26px; font-family: Tahoma; font-size: 10pt; ">容器JNDIl定 BeanManager?/span> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="color: #0000ff; font-size: 10pt; "><</span><span style="color: #800000; font-size: 10pt; ">Context</span><span style="color: #0000ff; font-size: 10pt; ">></span> <br /><span style="color: #0000ff; font-size: 10pt; ">   <</span><span style="color: #800000; font-size: 10pt; ">Manager </span><span style="color: #ff0000; font-size: 10pt; ">pathname</span><span style="color: #0000ff; font-size: 10pt; ">=""</span><span style="color: #0000ff; font-size: 10pt; ">/></span> <span style="color: #008000; font-size: 10pt; "><!--</span><span style="color: #008000; font-size: 10pt; "> disables storage of sessions across restarts </span><span style="color: #008000; font-size: 10pt; ">--></span><br />   <span style="color: #0000ff; font-size: 10pt; "><</span><span style="color: #800000; font-size: 10pt; ">Resource </span><span style="color: #ff0000; font-size: 10pt; ">name</span><span style="color: #0000ff; font-size: 10pt; ">="BeanManager"</span><span style="color: #FF0000; "><br /></span><span style="color: #ff0000; font-size: 10pt; ">      auth</span><span style="color: #0000ff; font-size: 10pt; ">="Container"</span><span style="color: #FF0000; "><br /></span><span style="color: #ff0000; font-size: 10pt; ">      type</span><span style="color: #0000ff; font-size: 10pt; ">="javax.enterprise.inject.spi.BeanManager"</span><span style="color: #FF0000; "><br /></span><span style="color: #ff0000; font-size: 10pt; ">      factory</span><span style="color: #0000ff; font-size: 10pt; ">="org.jboss.weld.resources.ManagerObjectFactory"</span><span style="color: #0000ff; font-size: 10pt; ">/></span><br />   <span style="color: #008000; font-size: 10pt; "><!--</span><span style="color: #008000; font-size: 10pt; "> Uncomment to enable injection into Servlet </span><span style="color: #008000; font-size: 10pt; ">--></span><br />   <span style="color: #008000; font-size: 10pt; "><!--</span><span style="color: #008000; font-size: 10pt; "> <Listener className="org.jboss.weld.environment.tomcat.WeldLifecycleListener"/> </span><span style="color: #008000; font-size: 10pt; ">--></span><br /><span style="color: #0000ff; font-size: 10pt; "></</span><span style="color: #800000; font-size: 10pt; ">Context</span><span style="color: #0000ff; font-size: 10pt; ">></span></div><span style="font-size: 10pt; ">    5Q在web.xml中,声明注册q个l定<br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> <span style="color: #0000ff; font-size: 10pt; "><</span><span style="color: #800000; font-size: 10pt; ">resource-env-ref</span><span style="color: #0000ff; font-size: 10pt; ">></span><br />      <span style="color: #0000ff; font-size: 10pt; "><</span><span style="color: #800000; font-size: 10pt; ">description</span><span style="color: #0000ff; font-size: 10pt; ">></span><span style="font-size: 10pt; ">Object factory for the CDI Bean Manager</span><span style="color: #0000ff; font-size: 10pt; "></</span><span style="color: #800000; font-size: 10pt; ">description</span><span style="color: #0000ff; font-size: 10pt; ">></span><br />      <span style="color: #0000ff; font-size: 10pt; "><</span><span style="color: #800000; font-size: 10pt; ">resource-env-ref-name</span><span style="color: #0000ff; font-size: 10pt; ">></span><span style="font-size: 10pt; ">BeanManager</span><span style="color: #0000ff; font-size: 10pt; "></</span><span style="color: #800000; font-size: 10pt; ">resource-env-ref-name</span><span style="color: #0000ff; font-size: 10pt; ">></span><br />      <span style="color: #0000ff; font-size: 10pt; "><</span><span style="color: #800000; font-size: 10pt; ">resource-env-ref-type</span><span style="color: #0000ff; font-size: 10pt; ">></span><span style="font-size: 10pt; ">javax.enterprise.inject.spi.BeanManager</span><span style="color: #0000ff; font-size: 10pt; "></</span><span style="color: #800000; font-size: 10pt; ">resource-env-ref-type</span><span style="color: #0000ff; font-size: 10pt; ">></span><br />   <span style="color: #0000ff; font-size: 10pt; "></</span><span style="color: #800000; font-size: 10pt; ">resource-env-ref</span><span style="color: #0000ff; font-size: 10pt; ">></span></div><span style="font-size: 10pt; ">    6Q在WEB-INF下面Q放一个空的bean.xml</span><span style="font-size: 10pt; "><br /><br /></span>    <span style="font-size: 10pt; ">在非jee6 或?非servlet容器下,都需要这样配|的。在Jboss as7中就要简单的多,只需要加?cdi-api.jar 跟一?bean.xml  其他的地方就是jsf的一些配|?/span><span style="font-size: 10pt; "><br /><br /></span>    <p> </p><h2><span style="font-size: 18pt; font-family: Arial; color: #993366; "><strong>二、上下文(Context)</strong></span></h2>    <br />    <span style="font-size: 10pt; ">Weld 中有5个上下文范围的容器:Request、Session、Application、Dependent ?Conversation。前?个就不再介绍了,他们的注解分别ؓ@RequestScoped @SessionScoped @ApplicationScoped 。JSR299中参照了SeamQ加入了一个新的会话范?Conversation<br /></span><span style="font-size: 18pt; font-family: Arial; color: #993366; "><strong>   </strong><span style="font-size: 10pt; color: #000000; "><strong>@Dependent  </strong>默认范围Q所有没有定义的上下文范围的Class或者Interface hq个默认的注解。用EL表达式每ơ应用一个Dependent范围的bean容器都会重新实例化一个。所以不要用EL应用Dependent范围的bean。每ơ注入这个范围的bean的时候,容器都会new一个新的实例给注入炏V?br /></span></span>    <strong style="font-size: 10pt; ">@Conversation </strong><span style="font-size: 10pt; ">可以叫它对话范围Q它的范围比Request大,一个Conversation里面可以包含多个RequestQ比Session范围?需要注意的一点,Conversation范围和Session范围的bean会被持久化到你的盘上,从而节省你的内存,所以在使用q两个范围的bean的时候需要实现序列化接口(Serializable)?br /></span>    <span style="font-size: 10pt; ">在实际应用中QConversation一般用于用多个页面来做一件事情,相关的对象不会丢失。但是,Conversation范围q不是它的对象放在Session中,只是在HttpSessionq个对象中存放了一个id?br /></span>    <span style="font-size: 10pt; ">Conversation 可以分ؓ短对话和长对话两U情c对于一般的ConversationQ它的持l时间是跟Request一LQƈ没有太大的区别。下面的方式可以把一个短对话变成长对话?br /></span><p> </p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">1</span> @Inject<br /><span style="color: #008080; ">2</span> Conversation conversation;<br /><span style="color: #008080; ">3</span> <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> start(){<br /><span style="color: #008080; ">4</span>     conversation.start();<br /><span style="color: #008080; ">5</span>     conversation.setTimeout(30000);<span style="color: #008000; ">//</span><span style="color: #008000; ">5分钟Q默?0分钟</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">6</span> <span style="color: #008000; "></span>}</div>    <span style="font-size: 10pt; "><br /><br /></span><h2><span style="color: #993366; font-size: 18pt; "><strong>三、依赖注?@Inject</strong></span></h2>    <span style="color: #000000; font-size: 10pt; ">JSR299 借鉴了现在很行的依赖注入,自己通过注解也实C依赖注入Q无需像Spring那么多的配置文g?br /><br /></span>    <span style="font-size: 10pt; font-family: Tahoma; ">weld 的三个注入点Q?br /></span>        <span style="font-size: 10pt; ">1. </span><span style="font-family: Tahoma; font-size: 10pt; ">构造方法参敎ͼ如果在一个bean的构造函C加上@Inject注解Q那么它的参数都是通过依赖注入传入的。也可以把@Inject攑֜形参的前面?br /></span>        <span style="font-size: 10pt; ">2. 初始化方法参敎ͼ如果一个方法上有@Inject注解Q它不是构造函数的话,上面q中情况Q那么这个方法就?</span><span style="font-size: 10pt; "><strong><font color="#ff9900">初始化方?</font> </strong>。初始化ҎL会在构造函C后执行,注入他的参数?br /></span>        <span style="font-size: 10pt; ">3. cd?span style="font-size: 10pt; ">: q也是最常用的一U方法,cM与seam2?@in ?br /><br /></span></span>    <span style="font-size: 10pt; ">下面分别l出q?中情늚例子<br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Inject<br /><span style="color: #0000FF; ">public</span> HelloAction(CurrentUser user){<br />}</div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Inject<br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> sayHello(CurrentUser user){<br />   System.out.println("Hello, "+user.getName());<br />}</div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Inject<br />Logger logger;</div><span style="font-size: 18pt; font-family: Arial; color: #993366; "><br /></span><h2><span style="font-size: 18pt; font-family: Arial; color: #993366; ">四、限定词 @Qualifier</span></h2>    <br />     <span style="font-size: 10pt; ">我们一般在注入service层的bean的时候,一般会直接注入一个接口,而不是它的实现类?/span><span style="font-size: 10pt; ">限定词的作用主要用于区分一个接口的不同实现?/span><br />    <span style="font-size: 10pt; ">weld 中有两个默认的限定词 @Default ?@AnyQ? <br /></span>        <span style="font-size: 10pt; ">@Default  Q?默认限定词,如果一个注入点没指定特定的限定词,那么它就默认使用@Defaultq个限定词?br /></span>        <span style="font-size: 10pt; ">@AnyQ?如果你一个接口有多个实现c,不同的实现类你用了不同的限定词来区分,那么 @Any 可以修饰所有的实现?/span><span style="font-size: 18pt; font-family: Arial; color: #993366; "><br /></span>   <span style="font-size: 10pt; ">一般情况,</span><span style="font-size: 10pt; ">需要我们自己定义个注解Q?br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Qualifier<br />@Retention(RetentionPolicy.RUNTIME)<br />@Target(ElementType.TYPE,Element.METHOD,ElementType.FIEID,ElementType.PARAMENTER)<br /><span style="color: #0000FF; ">public</span> @<span style="color: #0000FF; ">interface</span> Morning{}</div>    <span style="font-size: 10pt; ">@Qualifier 说明q个新定义的注解是一个限定词?br /></span>    <span style="font-size: 10pt; ">@Retention 表明q个注解什么时候作用,一般都是写 RUNTIME<br /></span>    <span style="font-size: 10pt; ">@Target 表明q个注解可以在什么地方用,上面的定义分别是 cd上,Ҏ上,属性,参数<br /></span>    <span style="font-size: 10pt; "><br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Inject @Morning HelloAction helloAction;</div><span style="font-size: 10pt; "><br /></span>    <span style="font-size: 10pt; ">如果一个接口有很多个实现类的话Q我们也不需要ؓ每个实现cd义一个注解。我们可以给一个注解加个参敎ͼ通过q个参数来指定注入哪个实现类?nbsp;<br /></span><span style="font-size: 10pt; "></span>    <span style="font-size: 10pt; ">只需要在个实现类之前加上q个限定词,那么在注入这个接口的时候,׃自动注入q个实现cM?/span>   <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><div>@Morning</div><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> MorningHelloAction Implements HelloAction{<br />    ...<br />}</div>    <span style="font-size: 10pt; ">一个bean如果实现了多个接口,那么只要d多个限定词就可以了?br /></span>    <span style="font-size: 10pt; ">使用了限定词Q这样在使用一个接口的时候,我现在不需要关心这个接口实现类的类名,只要你的实现cd了这个限定词Q在注入的时候就会自动找到这个类注入q来。这样可以大大的降低了耦合性?/span><span style="font-size: 18pt; font-family: Arial; color: #993366; "><br /><br /><br /></span><p> </p></div><img src ="http://www.aygfsteel.com/FORRogue/aggbug/370600.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/FORRogue/" target="_blank">Rogue</a> 2012-02-23 23:26 <a href="http://www.aygfsteel.com/FORRogue/archive/2012/02/23/370600.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ױ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̽</a>| <a href="http://" target="_blank">β</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">żҸ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ԭ</a>| <a href="http://" target="_blank">ϲ</a>| <a href="http://" target="_blank">Ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">°Ͷ</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">¬</a>| <a href="http://" target="_blank">ʡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ժ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Դ</a>| <a href="http://" target="_blank">˹</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ȫ</a>| <a href="http://" target="_blank">Ϸ</a>| <a href="http://" target="_blank">Զ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>