Interceptor issue with Java EE7

I am testing / switching to Java EE7 (Glassfish 4), and one of the problems that I have with Interceptors, whenever I try to start a project, I get the following error.

SEVERE: application loading exception: CDI deployment failure: WELD-001417 The interceptor class com.xxxxxx.security.SecuredInterceptor in file: / home / xxxxxx / xxxxxx / target / xxxxxx / WEB-INF / beans.xml @ 7 is neither annotated @Interceptor and not registered via portable extension

I look at section 1.3.6 of the CDI 1.1 specification, it doesn’t look like something has changed, so what am I doing wrong?

Here is the code I'm using;

@InterceptorBinding @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) public @interface Secured {} 

 @Secured @Interceptor public class SecuredInterceptor implements Serializable { @AroundInvoke public Object interceptSecured(InvocationContext ic) throws Exception { // Do Stuff } } 

 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="annotated"> <interceptors> <class>com.xxxxxx.security.SecuredInterceptor</class> </interceptors> </beans> 
+6
source share
2 answers

From section 12.1 of the CDI specification.

A bean archive containing the beans.xml file without version has a default bean detection mode for everyone.

Your version 1.1 beans.xml has bean-discovery-mode="annotated" . Change beans.xml to bean-discovery-mode="all" and I assume that it will work the same way as when uninstalling the version from beans.xml and use the old namespace as in CDI 1.0.

+4
source

This seems to be a Glassfish bug related to beans.xml version 1.1

https://java.net/jira/browse/GLASSFISH-20667

+1
source

Source: https://habr.com/ru/post/947927/


All Articles