Skip to content

Commit 18c24fc

Browse files
committed
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.
1 parent 9da3d25 commit 18c24fc

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.openejb.cdi;
18+
19+
import org.apache.webbeans.config.WebBeansContext;
20+
import org.apache.webbeans.container.InjectionResolver;
21+
22+
import jakarta.enterprise.inject.spi.Bean;
23+
import java.lang.annotation.Annotation;
24+
import java.lang.reflect.Type;
25+
import java.util.Set;
26+
27+
/**
28+
* A WAR and its parent EAR live in separate CDI bean archives. OWB's default
29+
* {@link InjectionResolver} does not cross BDA boundaries, so an injection
30+
* point in a WAR cannot see beans from a library jar bundled in the parent
31+
* EAR. When the WAR's own resolution returns an empty set, fall back to the
32+
* parent application's resolver so EAR-scoped beans stay visible to the WAR.
33+
*/
34+
public class WebAppInjectionResolver extends InjectionResolver {
35+
private final WebBeansContext context;
36+
37+
public WebAppInjectionResolver(final WebBeansContext ctx) {
38+
super(ctx);
39+
this.context = ctx;
40+
}
41+
42+
@Override
43+
public Set<Bean<?>> implResolveByType(final boolean delegate, final Type injectionPointType,
44+
final Class<?> injectionPointClass, final Annotation... qualifiers) {
45+
final Set<Bean<?>> set = super.implResolveByType(delegate, injectionPointType, injectionPointClass, qualifiers);
46+
if (set.isEmpty() && context instanceof WebappWebBeansContext wwbc && wwbc.getParent() != null) {
47+
return wwbc.getParent().getBeanManagerImpl().getInjectionResolver()
48+
.implResolveByType(delegate, injectionPointType, injectionPointClass, qualifiers);
49+
}
50+
return set;
51+
}
52+
}

container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public WebappBeanManager(final WebappWebBeansContext ctx) {
5959
super(ctx);
6060
webappCtx = ctx;
6161
deploymentBeans = super.getBeans(); // use the parent one while starting
62+
Reflections.set(this, "injectionResolver", new WebAppInjectionResolver(ctx));
6263
filter = new InheritedBeanFilter(this);
6364
}
6465

0 commit comments

Comments
 (0)