我有一个拦截器,当我在 Web 应用程序中使用它时,它似乎被 JBoss(EAP 6.4)正确加载,但当我在weld-se 上下文中使用相同的 beans.xml 时被拒绝。
package com.stackoverflow;
import javax.enterprise.context.Dependent;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
@Interceptor
@BindingAnnotation
@Dependent
public class InterceptorTest {
@AroundInvoke
public Object crypto(InvocationContext invocationContext) throws Exception {
return null;
}
}
和一个测试:
package com.stackoverflow;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.Before;
import org.junit.Test;
public class InterceptorTestTest {
WeldContainer container;
@Before
public void setup(){
Weld weld = new Weld();
container = weld.initialize();
}
@Test
public void crypto() throws Exception {
}
}
当我运行测试时:
[main] INFO org.jboss.weld.Version - WELD-000900 1.1.28 (Final)
[main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
org.jboss.weld.exceptions.DeploymentException: WELD-001417 Enabled interceptor class <class>com.stackoverflow.InterceptorTest</class> in file:/Users/pstanden/IdeaProjects/crypto/test/target/test-classes/META-INF/beans.xml@7 is neither annotated @Interceptor nor registered through a portable extension
at org.jboss.weld.bootstrap.Validator.validateEnabledInterceptorClasses(Validator.java:503)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:373)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:379)
at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.validateBeans(ForwardingBootstrap.java:85)
我真的不知道应该添加或删除什么,为什么 Weld org.jboss.weld.se:weld-se:1.1.28.Final 似乎对 JBoss 中的同一个版本的焊接做不同的事情?
编辑:我的 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>com.stackoverflow.InterceptorTest</class>
</interceptors>
</beans>
再次编辑我的pom:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.stackoverflow</groupId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<modelVersion>4.0.0</modelVersion>
<artifactId>test</artifactId>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>1.1.28.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.javaee</groupId>
<artifactId>javaee</artifactId>
<version>6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</project>