You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rz...@apache.org on 2026/04/21 10:56:53 UTC
(tomee) branch main updated: Restore cross-BDA injection fallback for WAR inside EAR
This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/main by this push:
new 18c24fc9eb Restore cross-BDA injection fallback for WAR inside EAR
18c24fc9eb is described below
commit 18c24fc9eb81a547413599836e6b81d25da42e54
Author: Richard Zowalla <rz...@apache.org>
AuthorDate: Tue Apr 21 12:56:37 2026 +0200
Restore cross-BDA injection fallback for WAR inside EAR
TOMEE-4600 removed the openejb.cache.cdi-type-resolution-failure feature and,
as collateral, also deleted WebAppInjectionResolver and its installation in
WebappBeanManager. That resolver's fallback allowed a WAR's BeanManager to
resolve beans declared in its parent EAR's library jars, which OWB's stock
InjectionResolver does not do. Without it, CdiParentBeanTest fails with
UnsatisfiedResolutionException for @Inject references from WAR code to
EAR-lib CDI beans.
Reintroduce a minimal WebAppInjectionResolver that only contains the
cross-BDA fallback (the cache-resolution-failure infrastructure stays
removed) and reinstall it from the WebappBeanManager constructor.
---
.../openejb/cdi/WebAppInjectionResolver.java | 52 ++++++++++++++++++++++
.../org/apache/openejb/cdi/WebappBeanManager.java | 1 +
2 files changed, 53 insertions(+)
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebAppInjectionResolver.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebAppInjectionResolver.java
new file mode 100644
index 0000000000..52aa498473
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebAppInjectionResolver.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.cdi;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.InjectionResolver;
+
+import jakarta.enterprise.inject.spi.Bean;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+/**
+ * A WAR and its parent EAR live in separate CDI bean archives. OWB's default
+ * {@link InjectionResolver} does not cross BDA boundaries, so an injection
+ * point in a WAR cannot see beans from a library jar bundled in the parent
+ * EAR. When the WAR's own resolution returns an empty set, fall back to the
+ * parent application's resolver so EAR-scoped beans stay visible to the WAR.
+ */
+public class WebAppInjectionResolver extends InjectionResolver {
+ private final WebBeansContext context;
+
+ public WebAppInjectionResolver(final WebBeansContext ctx) {
+ super(ctx);
+ this.context = ctx;
+ }
+
+ @Override
+ public Set<Bean<?>> implResolveByType(final boolean delegate, final Type injectionPointType,
+ final Class<?> injectionPointClass, final Annotation... qualifiers) {
+ final Set<Bean<?>> set = super.implResolveByType(delegate, injectionPointType, injectionPointClass, qualifiers);
+ if (set.isEmpty() && context instanceof WebappWebBeansContext wwbc && wwbc.getParent() != null) {
+ return wwbc.getParent().getBeanManagerImpl().getInjectionResolver()
+ .implResolveByType(delegate, injectionPointType, injectionPointClass, qualifiers);
+ }
+ return set;
+ }
+}
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
index 8cdc657953..652344c295 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
@@ -59,6 +59,7 @@ public class WebappBeanManager extends BeanManagerImpl {
super(ctx);
webappCtx = ctx;
deploymentBeans = super.getBeans(); // use the parent one while starting
+ Reflections.set(this, "injectionResolver", new WebAppInjectionResolver(ctx));
filter = new InheritedBeanFilter(this);
}