我的wildfly-swarm应用程序遇到了一个奇怪的问题。 我有一个像这样定义的JAX-RS服务,注释和RequestFilter
FooService.java
@Path("/foo")
@RequestScoped
@Api(value = "foo")
public class FooService extends BaseService {
@GET
@Produces({MediaType.APPLICATION_JSON})
@ApiOperation(...)
@ApiResponses(...)
@Secured({UserGroup.USER})
public Response getBar(@ApiParam(...) @QueryParam("id") int id) {
return Response.ok("bar").build();
}
}
BaseService.java
public class BaseService {
...
}
Secured.java
@NameBinding
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Secured {
UserGroup[] value() default {};
}
FooFilter.java
@Secured
@Provider
@Priority(Priorities.AUTHENTICATION)
public class FooFilter extends BaseService implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) {
...
}
}
据我所知,每次请求GET / foo时都应该调用FooFilter.filter()。使用Wildfly 12一切正常,但运行我的wildfly-swarm应用程序FooFilter.filter()永远不会被调用。 有什么建议吗?
为了完成,这是我的pom文件中的依赖项。
<!-- Java EE 7 dependency --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> <!-- WildFly Swarm Fractions --> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>cdi</artifactId> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>ejb</artifactId> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>jaxrs</artifactId> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>jpa</artifactId> <exclusions> <exclusion> <groupId>org.wildfly.swarm</groupId> <artifactId>h2</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>transactions</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${version.mysql}</version> </dependency>
提前致谢!
答案 0 :(得分:0)
愚蠢的我。我搞定了。 我刚刚添加了
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
//Filter
classes.add(FooFilter.class);
return classes;
}
到我的Application类。 Wildfly swarm基于Wildfly 11而不是12. 11使用RestEasy 3.0.24作为JAX-RS实现,12使用RestEasy 3.5。
似乎RestEasy 3.0.24需要手动注册RequestFilter,而3.5则不需要。