有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

EJB中不调用java CDI拦截器

我试图在Wildfly 8.2的EJB中使用类似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.");
    }

    .
    .
}


豆。xml

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

共 (0) 个答案