Seems that, on AS 7, the beans.xml inside cdijar is being ignored. Is that the correct behaviour?
It's not ignored.
AS7 Weld integration is different from AS6, wrt CDI archives.
AS6 is more flat ~ CDI / (sub)deployment, whereas AS7 is CDI / bean archive.
In order for the interceptor to kick in, you would need to define it in .war' beans.xml.
We didn't get the point of that. For example, if my app depends on a .jar that defines an interceptor in its beans.xml I need to redefine it in the war's beans.xml in order to use it?
As an additional test we've deployed the same app (https://github.com/zyc/jboss-as7-lab/tree/master/interceptors/scenario1) on tomcat7. To achieve that we've created a Maven profile, added the Weld listener (org.jboss.weld.environment.servlet.Listener) in web.xml and added a dependency to the newest Weld lib (1.1.2.AS7). That works just fine.
Thanks in advance,
According to section 12.1 (Bean archives) of CDI specification, "When searching for beans, the container considers: (...) any interceptor or decorator class declared in the beans.xml file of any bean archive".
Additionally at top of section 12: "Bean discovery is the process of determining: The bean archives that exist in the application, and the beans they contain; Which alternatives, interceptors and decorators are enabled for each bean archive; (...)"
Would the correct behavior considers beans.xml into the library jar (cdijar) in the way that Wilson referred?
The two relevant sections are:
9.4 - "By default, a bean archive has no enabled interceptors bound via interceptor bindings. An interceptor must be explicitly
enabled by listing its class under the <interceptors> element of the beans.xml file of the bean archive."
9.5 - "An interceptor is bound to the method if: .....
The interceptor is enabled in the bean archive containing the bean."
I agree that this behaviour is not ideal, but we have to follow the spec.
Thanks for complementation, Stuart. This is exactily what we mean on the first post: "Seems that, on AS 7, the beans.xml inside cdijar is being ignored. Is that the correct behaviour?".
According to specification, the beans.xml inside "cdijar" which defines the interceptor should be considered... or not? If you run the example app you will notice that AS7 apparently does not follow the spec at this point.
The beans.xml if cdijar is only considered for beans deployed inside cdijar. If the beans.xml in cdijar defines enables an interceptor, it is only applied to beans that are packaged inside cdijar.
Beans in WEB-INF/classes will not be intercepted unless the interceptors are enabled again in META-INF/beans.xml of the war archive.
In META-INF/beans.xml or WEB-INF/beans.xml ????
Hi Guys, I am pretty late with my note, but....
Say I have tree jars in a war archive. One of jars provides interceptor bindings and interceptors themselfs. Two other jars uses binding annotations and want to use interceptor. If I follow you, I would have to define interceptors in each of two jar. It would work probably in AS7 (haven't try it). But it does not work in other containers, when weld is deployed together with web application. The exception would be double interceptor registration.