Hi Marcin,
Only annotations with @Target({ElementType.METHOD, ElementType.TYPE}) or
@Target({ElementType.TYPE}) can be interceptor bindings (chapter 1 of the spec).
CDI interceptors cannot be defined for constructors per se (so there's no
around-constructor semantics), but you can have a @PostConstruct method on a
@Target({ElementType.TYPE}) interceptor, which effectively executes after the instance has
been created and CDI-injected.
Hope this helps,
Marius
On 2010-07-17, at 5:36 PM, Marcin ZajÄ…czkowski wrote:
Hi,
I'm trying to write mocked unit tests for my interceptor using
mechanisms given by AbstractWeldTest and jboss-test-harness package.
My test class extends AbstractWeldTest, had Artifact and WebBeans
(pointing to beans.xml with my interceptor defined) annotations.
My interceptor seems normal for me:
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@InterceptorBinding
public @interface Perf4jProfiled {
}
When I run a very simple test, I've got:
23:06:53.505 [main] DEBUG org.jboss.weld.Reflection - WELD-000602
interface net.sf.perf4cdi.api.Perf4jProfiled is not declared
@Target(TYPE, METHOD) or @Target(TYPE)
org.jboss.weld.exceptions.DeploymentException: WELD-000069 An
interceptor must have at least one binding, but
net.sf.perf4cdi.Perf4jProfiledInterceptor has none
at org.jboss.weld.bean.InterceptorImpl.<init>(InterceptorImpl.java:71)
at org.jboss.weld.bean.InterceptorImpl.of(InterceptorImpl.java:55)
at
org.jboss.weld.bootstrap.AbstractBeanDeployer.createInterceptor(AbstractBeanDeployer.java:255)
at org.jboss.weld.bootstrap.BeanDeployer.createBeans(BeanDeployer.java:106)
at
org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:151)
at
org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:377)
at
org.jboss.weld.mock.MockServletLifecycle.beginApplication(MockServletLifecycle.java:121)
at org.jboss.weld.mock.TestContainer.startContainer(TestContainer.java:85)
at
org.jboss.weld.test.harness.AbstractStandaloneContainersImpl.deploy(AbstractStandaloneContainersImpl.java:40)
at org.jboss.testharness.AbstractTest.deployArtifact(AbstractTest.java:103)
at org.jboss.testharness.AbstractTest.beforeClass(AbstractTest.java:206)
at
org.jboss.weld.test.AbstractWeldTest.beforeClass(AbstractWeldTest.java:57)
When I remove CONSTRUCTOR it works better (there is another problem, but
not related I have to debug it).
I would like to ask if this is a limitation of CDI that an interceptor
cannot be put on constructor?
Regards
Marcin
_______________________________________________
weld-dev mailing list
weld-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/weld-dev