diff --git a/impl/src/main/java/org/jboss/weld/interceptor/util/InterceptionTypeRegistry.java b/impl/src/main/java/org/jboss/weld/interceptor/util/InterceptionTypeRegistry.java index 1926f6ef2b4..b36207adba0 100644 --- a/impl/src/main/java/org/jboss/weld/interceptor/util/InterceptionTypeRegistry.java +++ b/impl/src/main/java/org/jboss/weld/interceptor/util/InterceptionTypeRegistry.java @@ -44,7 +44,9 @@ private InterceptionTypeRegistry() { try { interceptionAnnotationClasses.put(interceptionType, (Class) InterceptionTypeRegistry.class.getClassLoader().loadClass(interceptionType.annotationClassName())); } catch (Exception e) { - InterceptorLogger.LOG.interceptorAnnotationClassNotFound(interceptionType.annotationClassName()); + if (InterceptionUtils.isAnnotationClassExpected(interceptionType)) { + InterceptorLogger.LOG.interceptorAnnotationClassNotFound(interceptionType.annotationClassName()); + } } } INTERCEPTOR_ANNOTATION_CLASSES = Collections.unmodifiableMap(interceptionAnnotationClasses); diff --git a/impl/src/main/java/org/jboss/weld/interceptor/util/InterceptionUtils.java b/impl/src/main/java/org/jboss/weld/interceptor/util/InterceptionUtils.java index ed951dc95ed..17f8a78fbb5 100644 --- a/impl/src/main/java/org/jboss/weld/interceptor/util/InterceptionUtils.java +++ b/impl/src/main/java/org/jboss/weld/interceptor/util/InterceptionUtils.java @@ -19,16 +19,27 @@ import java.util.concurrent.Callable; +import org.jboss.weld.bootstrap.api.Environment; +import org.jboss.weld.bootstrap.api.Environments; import org.jboss.weld.interceptor.proxy.InterceptorException; import org.jboss.weld.interceptor.proxy.LifecycleMixin; +import org.jboss.weld.interceptor.spi.model.InterceptionType; +import org.jboss.weld.resources.WeldClassLoaderResourceLoader; +import org.jboss.weld.util.reflection.Reflections; /** * @author Marius Bogoevici */ public class InterceptionUtils { + public static final String POST_CONSTRUCT = "lifecycle_mixin_$$_postConstruct"; + public static final String PRE_DESTROY = "lifecycle_mixin_$$_preDestroy"; + private static final String WELD_SE_CLASS = "org.jboss.weld.environment.se.Weld"; + + private static final String WELD_SERVLET_CLASS = "org.jboss.weld.environment.servlet.WeldServletLifecycle"; + private InterceptionUtils() { } @@ -67,4 +78,25 @@ private static void executePredestroy(Object proxy, Callable callback) { public static void executePredestroy(Object proxy) { executePredestroy(proxy, null); } + + static boolean isAnnotationClassExpected(InterceptionType interceptionType) { + if (InterceptionType.POST_ACTIVATE.equals(interceptionType) || InterceptionType.PRE_PASSIVATE.equals(interceptionType)) { + Environment environment = detectEnvironment(); + if (environment != null && (Environments.SE.equals(environment) || Environments.SERVLET.equals(environment))) { + return false; + } + } + return true; + } + + private static Environment detectEnvironment() { + // We should rather use the environment from WeldStartup but it's not available in the static initializer + Environment environment = null; + if (Reflections.isClassLoadable(WELD_SE_CLASS, WeldClassLoaderResourceLoader.INSTANCE)) { + environment = Environments.SE; + } else if (Reflections.isClassLoadable(WELD_SERVLET_CLASS, WeldClassLoaderResourceLoader.INSTANCE)) { + environment = Environments.SERVLET; + } + return environment; + } }