问题描述
我正在尝试禁用位于bean存档罐中的类的2个观察者方法(更具体地说,是Seam 3 Faces模块的类LoginListener
),并改用我的地雷.
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.
我有一个Web项目,其中有一个bean存档:
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
在my-beans.jar
中,我有那个课:
@Alternative
public class MyLoginListener extends LoginListener {
@Override
public void observePostLoginEvent(final PostLoginEvent event) {
}
@Override
public void observePreLoginEvent(final PreLoginEvent event) {
}
}
然后,在my-beans.jar/META-INF/beans.xml
中,我将其激活:
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>
而且,app.war/WEB-INF/beans.xml
中的内容相同.
这里我不明白为什么,但是仍然是原始的LoginListener
observePostLoginEvent(@Observes PostLoginEvent event)
和observePreLoginEvent
被称为...有人知道为什么吗?
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 ?
推荐答案
您是否也尝试使用@Specializes(@Alternative @Specializes)注释您的课程?根据焊接参考这样您可以完全隐藏"另一个bean(及其生产者和观察者)
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)
这篇关于如何在网络应用程序中使用@Alternative扩展具体类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!