Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 38 java ee 8 public Employee getById int id return getWrapped getById id Note that in the produce method shown in the code immediately before this latest code I obtained an instance of the original EmployeeService class using CDI instead of just instantiating via the new operator This approach is needed for the injection in that bean to do its work and to apply the correct scope Earlier I mentioned a caveat it is difficult for an Interceptor implementation to access the interceptor bindings when they have been added dynamically That same caveat applies here The current JTA Interceptor implementations are not yet aware of CDI 20 and will not see the dynamic annotation and thus they will not be able to read its attributes Payara 5 will address this and I expect other implementations will soon do the same thing You should also be aware that the add methods of the InterceptionFactory will happily accept any type of annotation While CDI is widely known for its ability to inject beans into injection points it also features an API to look up beans programmatically literal but only those representing interceptor bindings will have any efect For instance interceptionFactory configure add SessionScoped Literal INSTANCE will both compile and not throw any exceptions at runtime but the produced bean will not be given the configured scope Programmatic Bean Lookup Simplifications While CDI is widely known for its ability to inject beans into injection points it also features an API to look up beans programmatically This API largely mimics the way injection works That is if you can create an injection point of type Foo with qualifier Bar then the same bean that
You must have JavaScript enabled to view digital editions.