My Java EE 6 application consists of a war and an ejb module packaged in ear file. I\'m using CDI for DI (i.e. I have a beans.xml file in both modules). I want to use a logging
If you have no control over the external dependency and you still want to enable interceptors without beans.xml you can write a CDI extension:
package my.package;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AfterTypeDiscovery;
import javax.enterprise.inject.spi.Extension;
public class MyCdiExtension implements Extension {
public void observeAfterTypeDiscovery(@Observes AfterTypeDiscovery afterTypeDiscovery) {
afterTypeDiscovery.getInterceptors().add(SomeExternalInterceptor.class);
}
}
Add file resources/META-INF/services/javax.enterprise.inject.spi.Extension
with content:
my.package.MyCdiExtension