Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 26 java ee 8 @ Observes AfterBeanDiscovery afterBeanDiscovery afterBeanDiscovery addBean scope ApplicationScoped class types MyBean class id Created by CdiExtension class createWith e new MyBeanImpl Hi This code makes an @ ApplicationScoped bean available for injection into MyBean injection points backed by the MyBeanImpl class In the example shown above the MyBeanImpl type is completely hidden and CDI will inject only into MyBean and nothing else If there were a need to inject into other related types the other types can be provided in the types method of the builder as well As with all CDI extensions the extension class has to be registered by putting its fully qualified name FQN in META INF services javax enterprise inject spi Extension Once all this is done the bean can be injected just like any other bean @ ApplicationScoped public class SomeBean @ Inject private MyBean myBean Programmatically Adding an Interceptor to a Built In CDI Bean In CDI beans can be augmented via two artifacts decorators and interceptors Decorators are typically owned by the application code and can decorate a bean thats shipped by the container built in beans or a library
You must have JavaScript enabled to view digital editions.