在EJB中不调用CDI拦截器

时间:2015-08-24 15:44:16

标签: java java-ee ejb cdi wildfly

我正在尝试在Wildfly 8.2上使用类似CDI的拦截器,但它们不会在任何EJB中调用。但是,它们与CDI对象一起正常工作。

@InterceptorBinding
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DataTransferObject {

}


拦截器将实体克隆到DTO作为返回;

@Interceptor
@DataTransferObject
public class DataTransferObjectInterceptor {

    @AroundInvoke
    public Object clone(InvocationContext invocationContext) throws Exception {
        Object actual = invocationContext.proceed();
        Object clone = actual.getClass().newInstance();
        BeanUtil.clone(actual, clone);
        return clone;
    }
}


拦截器并没有抓住这个;

@Stateless
@DataTransferObject
public class BaseCompanyService implements CompanyService {

    @EJB
    private CompanyDAO companyDAO;

    @Override
    public void create(Company entity) throws EntityException {
        companyDAO.create(entity);
    }

    .
    .
}


但它在这里工作正常;

@Path("/company")
@Produces(MediaType.APPLICATION_JSON)
@DataTransferObject
@Slf4j
public class CompanyResource implements Resource {

    @EJB
    private CompanyService companyService;

    @GET
    @Path("/check")
    @Override
    public Success check() {
        return new Success("The company service is running.");
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public Success create(@Valid Company entity) throws EntityException {
        companyService.create(entity);
        log.info("The company with id \"{}\" is successfully created.", entity.getId());
        return new Success("The company is successfully created.");
    }

    .
    .
}


beans.xml中

<interceptors>
    <class>io.rraa.interceptors.DataTransferObjectInterceptor</class>
</interceptors>

0 个答案:

没有答案