java互联网科技Java学习笔记

6-Spring-IoC概述

2018-04-06  本文已影响17人  宠辱不惊的咸鱼

概述

@Resource
AService aService;

public void doSomething() {
    aService.doSomenthing();
}
@Stateless  
@EJB(name="audit", beanInterface=AuditService.class)  
public class DepartmentServiceBean implements DepartmentService {  
    private AuditService audit;  
      
    @PostConstruct  
    public void init() {
        try {
            Context ctx = new InitialContext();
            audit = (AuditService) ctx.lookup("java:comp/env/audit");
        } catch (NamingException e) {
            throw new EJBException(e);
        }
    }
  
    public void performAudit() {
        audit.audit();
    }
}
上一篇 下一篇

猜你喜欢

热点阅读