Java Reference
In-Depth Information
won't trigger the
SecuredAuditedInterceptor
because only the
@Secured
an-
notation is applied to the method. But add
@Audited
to the method:
@Stateless
public class BidService {
...
@Secured @Audited
public void removeBid(Bid bid) {
bidDao.removeBid(bid);
}
}
In this example, both annotations are added to
removeBid()
so the
Se-
curedAuditedInterceptor
will now be invoked. Now move
@Audited
to the
class level:
@Stateless
@Audited
public class BidService {
...
@Secured
public void removeBid(Bid bid) {
bidDao.removeBid(bid);
}
}
In this example,
SecuredAuditedInterceptor
will still be invoked because
@Audited
will be applied to every method in
BidService
, which includes
re-
moveBid()
. Because
removeBid()
is also annotated with
@Secured
,
Se-
curedAuditedInterceptor
will be called.
5.4. Summary
In this chapter we covered the EJB context, how to use the
@EJB
and
@Resource
annota-
tions for dependency injection, and how and when JNDI must be used to manually look up
EJBs and resources. We introduced aspect-oriented programming and showed how EJB in-
terceptors can be used to implement crosscutting concerns on EJB business logic. Finally,
we compared EJB interceptors with the more powerful CDI interceptors.