Is It Possible To Create New Interceptor In Weld SE
xsalefter.xsalefter.yahoo.com Aug 27, 2010 9:49 PMHi weld user and developer..
Recently I'm play with Weld-SE, and try to define and create an Interceptor like this:
@Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented @InterceptorBinding public @interface View { String value() default ""; } @Interceptor @View public class ViewControllerInterceptor { @AroundInvoke public Object aroundInvoke(InvocationContext ic) throws Exception { System.out.println("Did it." + ic.getTarget()); return ic.proceed(); } }
And this is my beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> <interceptors> <class>org.xsalefter.swingmvc.ViewControllerInterceptor</class> </interceptors> </beans>
But I get DeploymentException like this:
08:29:53,906 INFO [weld.Version] WELD-000900 1.0.1 (Final) 08:29:53,953 INFO [weld.Bootstrap] WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously. 08:29:54,828 WARN [model.InterceptionTypeRegistry] Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled 08:29:54,828 WARN [model.InterceptionTypeRegistry] Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: WELD-001416 Enabled interceptor class class org.xsalefter.swingmvc.ViewControllerInterceptor specified twice specified twice at org.jboss.weld.bootstrap.Validator.validateEnabledInterceptorClasses(Validator.java:445) at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:319) at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:399) at org.jboss.weld.environment.se.Weld.initialize(Weld.java:81) at org.jboss.weld.environment.se.StartMain.go(StartMain.java:45) at org.jboss.weld.environment.se.StartMain.main(StartMain.java:57) Java Result: 1
As far as I know from the stack trace seems that I can't create new Interceptor. My question is that, is it possible to define interceptor in weld like this? If yes, can someone help me to do it correctly?
Thanks.