AOP on Tomcat with Weld

AOP on Tomcat with Weld

我正在学习如何使用有关 RESTful 网络服务的 AOP。我选择 Tomcat 作为平台,Weld 引入 CDI,我还使用 CXF 作为 JAX-RS 实现(这是委员会特定的技术限制,我是新手)。这是我的 sandbox. 据我所知 Weld 已正确加载,我从 here 获得了 Tomcat + Weld 配置,它找到了我的拦截器(这里是日志快照):

...
2017-02-02 11:26:03 DEBUG Bootstrap:238 - WELD-000105: Enabled interceptor types for Weld BeanManager for /SecProof_/WEB-INF/classes [bean count=2]: 
  - class org.jboss.weld.context.activator.ActivateRequestContextInterceptor,
  - class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 DEBUG Bootstrap:236 - WELD-000103: Enabled alternatives for Weld BeanManager for org.jboss.weld.environment.deployment.WeldDeployment.additionalClasses [bean count=3]: (empty collection)
2017-02-02 11:26:03 DEBUG Bootstrap:237 - WELD-000104: Enabled decorator types for Weld BeanManager for org.jboss.weld.environment.deployment.WeldDeployment.additionalClasses [bean count=3]: (empty collection)
2017-02-02 11:26:03 DEBUG Bootstrap:238 - WELD-000105: Enabled interceptor types for Weld BeanManager for org.jboss.weld.environment.deployment.WeldDeployment.additionalClasses [bean count=3]: 
  - class org.jboss.weld.context.activator.ActivateRequestContextInterceptor
2017-02-02 11:26:03 INFO  servletTomcat:45 - WELD-ENV-001100: Tomcat 7+ detected, CDI injection will be available in Servlets, Filters and Listeners.
2017-02-02 11:26:03 TRACE Bean:300 - WELD-001536: Found [] constructors annotated with @Inject for [EnhancedAnnotatedTypeImpl] public @Path class edu.pezzati.sec.WebBoundary
2017-02-02 11:26:03 TRACE Bean:300 - WELD-001536: Found [] constructors annotated with @Inject for [EnhancedAnnotatedTypeImpl] public @CanAccess @Interceptor class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 TRACE Bean:309 - WELD-000002: Exactly one constructor ([EnhancedAnnotatedConstructorImpl] public edu.pezzati.sec.WebBoundary()) defined, using it as the bean constructor for [EnhancedAnnotatedTypeImpl] public @Path class edu.pezzati.sec.WebBoundary
2017-02-02 11:26:03 TRACE Bean:309 - WELD-000002: Exactly one constructor ([EnhancedAnnotatedConstructorImpl] public edu.pezzati.sec.CanAccessImpl()) defined, using it as the bean constructor for [EnhancedAnnotatedTypeImpl] public @CanAccess @Interceptor class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 TRACE Bean:300 - WELD-001536: Found [] constructors annotated with @Inject for [EnhancedAnnotatedTypeImpl] public @CanAccess @Interceptor class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 TRACE Bean:309 - WELD-000002: Exactly one constructor ([EnhancedAnnotatedConstructorImpl] public edu.pezzati.sec.CanAccessImpl()) defined, using it as the bean constructor for [EnhancedAnnotatedTypeImpl] public @CanAccess @Interceptor class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 TRACE Bean:300 - WELD-001536: Found [] constructors annotated with @Inject for [EnhancedAnnotatedTypeImpl] public @Path class edu.pezzati.sec.WebBoundary
...

好吧,我可以访问我的普通服务,但我的拦截器没有被触发。这是 Tomcat 给我的反馈:

...
INFORMAZIONI: Server startup in 2293 ms
2017-02-02 11:28:59 TRACE Servlet:232 - WELD-000708: Initializing request org.apache.catalina.connector.Request@2b2c4052
2017-02-02 11:28:59 DEBUG Reflection:82 - WELD-000620: interface javax.enterprise.inject.Intercepted is not declared @Target(METHOD, FIELD, PARAMETER, TYPE). Weld will use this annotation, however this may make the application unportable.
2017-02-02 11:28:59 DEBUG Reflection:82 - WELD-000620: interface javax.enterprise.inject.Decorated is not declared @Target(METHOD, FIELD, PARAMETER, TYPE). Weld will use this annotation, however this may make the application unportable.
2017-02-02 11:28:59 TRACE Context:69 - WELD-000222: Loading bean store org.jboss.weld.context.beanstore.http.LazySessionBeanStore@366ca776 map from session null
2017-02-02 11:28:59 TRACE DefaultListableBeanFactory:568 - No bean named 'org.apache.cxf.phase.PhaseManager' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@2c80a98d: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,sec,secproof]; root of factory hierarchy
2017-02-02 11:28:59 TRACE DefaultListableBeanFactory:568 - No bean named 'org.apache.cxf.policy.PolicyDataEngine' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@2c80a98d: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,sec,secproof]; root of factory hierarchy
2017-02-02 11:28:59 TRACE Servlet:293 - WELD-000709: Destroying request org.apache.catalina.connector.Request@2b2c4052
...

我错过了什么?

没关系。只是缺少配置。我必须使用 cxf-integration-cdi 才能使其正常工作 this blog post and this 示例是基础知识。感谢作者。