How to use @Alternative extending a concrete class, in a webapp?

自闭症网瘾萝莉.ら 提交于 2019-12-13 07:08:20

问题


I'm trying to disable 2 observer methods of a class which is in a beans archive jar (more specifically, the class LoginListener of Seam 3 Faces module), and use mines instead.

I have a web project, with a beans archive in it :

app.war
\- WEB-INF
  \- lib
    \- seam-faces-3.1.0.Final.jar
    |- my-beans.jar

In my-beans.jar I've got that class :

@Alternative
public class MyLoginListener extends LoginListener {
    @Override
    public void observePostLoginEvent(final PostLoginEvent event) {
    }

    @Override
    public void observePreLoginEvent(final PreLoginEvent event) {
    }
}

Then, in my-beans.jar/META-INF/beans.xml I activate it :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
    <alternatives>
        <class>com.mycompagny.MyLoginListener</class>
    </alternatives>
</beans>

And, same content in app.war/WEB-INF/beans.xml.

Here I don't understand why, but it's still the original LoginListener observePostLoginEvent(@Observes PostLoginEvent event) and observePreLoginEvent which are called... does somebody know why ?


回答1:


Did you try to annotate your class also with @Specializes (@Alternative @Specializes)? According to Weld Reference this way you can completely "hide" the other bean (with its producers and observers)



来源:https://stackoverflow.com/questions/9332311/how-to-use-alternative-extending-a-concrete-class-in-a-webapp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!