Skip to content

Commit 85f2308

Browse files
authored
Merge pull request #32822 from tjwatson/springSetContextFlag
Add internal config option to disabling setting the EE component context
2 parents bd213a6 + dbcf510 commit 85f2308

File tree

27 files changed

+705
-14
lines changed

27 files changed

+705
-14
lines changed

dev/com.ibm.ws.app.manager.springboot/resources/OSGI-INF/metatype/metatype.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
com.ibm.ws.jca.embeddedResourceAdapter">
3232
<AD id="type" name="internal" description="internal" type="String" default="spring" ibm:final="true"/>
3333
<AD id="applicationArgument" name="%applicationArgument.name" description="%applicationArgument.desc" required="false" type="String" cardinality="2147483647"/>
34+
<AD name="internal" description="internal use only"
35+
id="setEEContextOnStartup"
36+
ibm:beta="true"
37+
required="false"
38+
default="true"
39+
type="Boolean"/>
3440
</OCD>
3541
<Designate factoryPid="com.ibm.ws.app.manager.springappcfg">
3642
<Object ocdref="com.ibm.ws.app.manager.springappcfg"/>

dev/com.ibm.ws.app.manager.springboot/src/com/ibm/ws/app/manager/springboot/internal/SpringBootApplicationImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ public String getId() {
543543
private final Set<Runnable> shutdownHooks = new CopyOnWriteArraySet<>();
544544
private final AtomicBoolean uninstalled = new AtomicBoolean();
545545
private final List<String> appArgs;
546+
private final boolean setEEContextOnStartup;
546547
private volatile AtomicReference<String> applicationActivated;
547548

548549
public SpringBootApplicationImpl(ApplicationInformation<DeployedAppInfo> applicationInformation,
@@ -580,6 +581,9 @@ public SpringBootApplicationImpl(ApplicationInformation<DeployedAppInfo> applica
580581
} else {
581582
appArgs = Collections.emptyList();
582583
}
584+
585+
Object setEEContextOnStartup = applicationInformation.getConfigProperty(SpringConstants.APP_SET_EE_CONTEXT_ON_STARTUP);
586+
this.setEEContextOnStartup = Boolean.TRUE.equals(setEEContextOnStartup);
583587
}
584588

585589
private static SpringBootManifest getSpringBootManifest(ApplicationInformation<DeployedAppInfo> appInfo) throws UnableToAdaptException {
@@ -712,6 +716,10 @@ List<String> getAppArgs() {
712716
return appArgs;
713717
}
714718

719+
boolean setEEContextOnStartup() {
720+
return setEEContextOnStartup;
721+
}
722+
715723
@Override
716724
public Container createContainerFor(String id) throws IOException, UnableToAdaptException {
717725
Container container = setupContainer(applicationInformation.getPid(), rawContainer, factory, deployedAppServices);

dev/com.ibm.ws.app.manager.springboot/src/com/ibm/ws/app/manager/springboot/internal/SpringBootRuntimeContainer.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.concurrent.ExecutorService;
2222
import java.util.concurrent.Future;
2323

24+
import org.osgi.service.component.annotations.Activate;
2425
import org.osgi.service.component.annotations.Component;
2526
import org.osgi.service.component.annotations.ConfigurationPolicy;
2627
import org.osgi.service.component.annotations.Reference;
@@ -114,16 +115,19 @@ ClassLoader getClassLoader() {
114115
}
115116
}
116117

117-
@Reference
118-
private ExecutorService executor;
119-
@Reference
120-
private FutureMonitor futureMonitor;
121-
122-
@Reference
123-
private LibertyProcess libertyProcess;
124-
118+
private final ExecutorService executor;
119+
private final FutureMonitor futureMonitor;
120+
private final LibertyProcess libertyProcess;
125121
private final Map<String, ComponentMetaData> components = new ConcurrentHashMap<>();
126122

123+
@Activate
124+
public SpringBootRuntimeContainer(@Reference ExecutorService executor, @Reference FutureMonitor futureMonitor,
125+
@Reference LibertyProcess libertyProcess) {
126+
this.executor = executor;
127+
this.futureMonitor = futureMonitor;
128+
this.libertyProcess = libertyProcess;
129+
}
130+
127131
@Override
128132
public ModuleMetaData createModuleMetaData(ExtendedModuleInfo moduleInfo) throws MetaDataException {
129133
return new SpringModuleMetaData((SpringBootModuleInfo) moduleInfo);
@@ -141,6 +145,7 @@ public Future<Boolean> startModule(ExtendedModuleInfo moduleInfo) throws StateCh
141145

142146
private void invokeSpringMain(Future<Boolean> mainInvokeResult, SpringBootModuleInfo springBootModuleInfo) {
143147
final SpringBootApplicationImpl springBootApplication = springBootModuleInfo.getSpringBootApplication();
148+
final boolean setEEContextOnStartup = springBootApplication.setEEContextOnStartup();
144149
final Method main;
145150

146151
SpringBootComponentMetaData springBootComponentMetaData = ((SpringModuleMetaData) springBootModuleInfo.getMetaData()).getComponentMetaData();
@@ -156,7 +161,7 @@ private void invokeSpringMain(Future<Boolean> mainInvokeResult, SpringBootModule
156161
});
157162

158163
try {
159-
if (currentCmd == null) {
164+
if (setEEContextOnStartup && currentCmd == null) {
160165
accessor.beginContext(springBootComponentMetaData);
161166
}
162167
springBootApplication.registerSpringConfigFactory();
@@ -172,7 +177,7 @@ private void invokeSpringMain(Future<Boolean> mainInvokeResult, SpringBootModule
172177
Thread.currentThread().setContextClassLoader(previousTccl);
173178
return null;
174179
});
175-
if (currentCmd == null) {
180+
if (setEEContextOnStartup && currentCmd == null) {
176181
accessor.endContext();
177182
}
178183
}
@@ -186,7 +191,7 @@ private void invokeSpringMain(Future<Boolean> mainInvokeResult, SpringBootModule
186191
return null;
187192
});
188193
try {
189-
if (currentCmd == null) {
194+
if (setEEContextOnStartup && currentCmd == null) {
190195
accessor.beginContext(springBootComponentMetaData);
191196
}
192197
// get the application args to pass from the springBootApplication
@@ -215,7 +220,7 @@ private void invokeSpringMain(Future<Boolean> mainInvokeResult, SpringBootModule
215220
Thread.currentThread().setContextClassLoader(execPreviousTccl);
216221
return null;
217222
});
218-
if (currentCmd == null) {
223+
if (setEEContextOnStartup && currentCmd == null) {
219224
accessor.endContext();
220225
}
221226
}

dev/com.ibm.ws.app.manager.springboot/src/com/ibm/ws/app/manager/springboot/internal/SpringConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-2.0/
7-
*
7+
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
1010
* Contributors:
@@ -49,6 +49,7 @@ public final class SpringConstants {
4949
public static final String XMI_VIRTUAL_HOST_END = "\">\n" +
5050
"</webappbnd:WebAppBinding>";
5151
public static final String APP_ARGS = "applicationArgument";
52+
public static final String APP_SET_EE_CONTEXT_ON_STARTUP = "setEEContextOnStartup";
5253

5354
public static final String ID_VIRTUAL_HOST = "springBootVirtualHost-";
5455
public static final String ID_HTTP_ENDPOINT = "springBootHttpEndpoint-";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/main/java"/>
4+
<classpathentry kind="src" path="src/main/resources"/>
5+
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/bin/
2+
/bin_test/
3+
/generated/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>com.ibm.ws.springboot.fat20.programmatic.trans.app</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>bndtools.core.bndbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>bndtools.core.bndnature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
compileErrorAction=build
2+
eclipse.preferences.version=1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.8
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#*******************************************************************************
2+
# Copyright (c) 2025 IBM Corporation and others.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License 2.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-2.0/
7+
#
8+
# SPDX-License-Identifier: EPL-2.0
9+
#
10+
#*******************************************************************************
11+
-include= \
12+
~../cnf/resources/bnd/bundle.props, \
13+
~../cnf/resources/bnd/bundle.spring.props
14+
-nouses=true
15+
16+
bVersion=1.0
17+
18+
test.project: true
19+
instrument.disabled: true
20+
publish.wlp.jar.disabled: true
21+
22+
src: \
23+
src/main/java, \
24+
src/main/resources
25+
26+
# Specify bundles to be added to the classpath of a VM used in testing.
27+
# Entries in the -testpath instruction enable the Eclipse Package Explorer
28+
# to resolve compile dependencies for test classes. The instruction is not
29+
# required to build Spring Boot test artifacts. Each entry requies a
30+
# corresponding entry in file cnf/oss_depenendcies.maven.
31+
# Ref: https://bndtools.org/manual/packageexplorer.html
32+
33+
-testpath: \
34+
org.springframework.boot:spring-boot;${springBootVersion20}, \
35+
org.springframework.boot:spring-boot-autoconfigure;${springBootVersion20}, \
36+
\
37+
org.springframework:spring-beans;${springVersion20}, \
38+
org.springframework:spring-context;${springVersion20}, \
39+
org.springframework:spring-core;${springVersion20}, \
40+
org.springframework:spring-jdbc;${springVersion20}, \
41+
org.springframework:spring-tx;${springVersion20}, \
42+
org.springframework:spring-web;${springVersion20}, \
43+
org.slf4j:slf4j-api;version=1.7.36, \
44+
com.ibm.websphere.javaee.servlet.3.1

0 commit comments

Comments
 (0)