Skip to content

Commit aa32270

Browse files
authored
GH-3541: Properly guard when no json-path in CP (#3542)
Fixes #3541 * Fix `DefaultConfiguringBeanFactoryPostProcessor` to check for `jsonPath` bean a `com.jayway.jsonpath.JsonPath` on CP instead of `JsonPathUtils` which is always there since it is a part of `spring-integration-core` * Remove `json-path` and `jackson-databind` from tests classpath to be sure that we have coverage for the mentioned above option classpath entries * Add `json-path` and `jackson-databind` into test classpath whenever it is necessary
1 parent c57634f commit aa32270

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

build.gradle

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ configure(javaProjects) { subproject ->
249249
testImplementation 'org.jetbrains.kotlin:kotlin-reflect'
250250
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
251251
testImplementation 'io.projectreactor:reactor-test'
252-
testImplementation "com.jayway.jsonpath:json-path:$jsonpathVersion"
253-
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
254252

255253
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
256254
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
@@ -488,6 +486,7 @@ project('spring-integration-file') {
488486
testImplementation project(':spring-integration-jdbc')
489487
testImplementation "com.h2database:h2:$h2Version"
490488
testImplementation "io.lettuce:lettuce-core:$lettuceVersion"
489+
testImplementation "com.jayway.jsonpath:json-path:$jsonpathVersion"
491490
}
492491
}
493492

@@ -546,6 +545,9 @@ project('spring-integration-http') {
546545
testImplementation ("org.springframework.security:spring-security-test:$springSecurityVersion") {
547546
exclude group: 'org.springframework'
548547
}
548+
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
549+
550+
testRuntimeOnly "com.jayway.jsonpath:json-path:$jsonpathVersion"
549551
}
550552
}
551553

@@ -556,7 +558,9 @@ project('spring-integration-ip') {
556558
testImplementation project(':spring-integration-stream')
557559
testImplementation project(':spring-integration-event')
558560
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
561+
559562
testRuntimeOnly "com.esotericsoftware:kryo-shaded:$kryoShadedVersion"
563+
testRuntimeOnly 'com.fasterxml.jackson.core:jackson-databind'
560564
}
561565
}
562566

@@ -573,6 +577,8 @@ project('spring-integration-jdbc') {
573577
testImplementation "org.postgresql:postgresql:$postgresVersion"
574578
testImplementation "mysql:mysql-connector-java:$mysqlVersion"
575579
testImplementation "org.apache.commons:commons-dbcp2:$commonsDbcp2Version"
580+
581+
testRuntimeOnly 'com.fasterxml.jackson.core:jackson-databind'
576582
}
577583
}
578584

@@ -625,7 +631,6 @@ project('spring-integration-kafka') {
625631
testImplementation "org.springframework.kafka:spring-kafka-test:$springKafkaVersion"
626632
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
627633

628-
testRuntimeOnly 'com.fasterxml.jackson.core:jackson-core'
629634
testRuntimeOnly 'com.fasterxml.jackson.core:jackson-databind'
630635
}
631636
}
@@ -674,6 +679,7 @@ project('spring-integration-mqtt') {
674679
api "org.eclipse.paho:org.eclipse.paho.client.mqttv3:$pahoMqttClientVersion"
675680

676681
testImplementation project(':spring-integration-jmx')
682+
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
677683
}
678684
}
679685

@@ -687,6 +693,7 @@ project('spring-integration-redis') {
687693

688694
testImplementation "io.lettuce:lettuce-core:$lettuceVersion"
689695
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
696+
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
690697
}
691698
}
692699

@@ -806,6 +813,9 @@ project('spring-integration-webflux') {
806813
testImplementation ("org.springframework.security:spring-security-test:$springSecurityVersion") {
807814
exclude group: 'org.springframework'
808815
}
816+
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
817+
818+
testRuntimeOnly "com.jayway.jsonpath:json-path:$jsonpathVersion"
809819
}
810820
}
811821

@@ -818,6 +828,8 @@ project('spring-integration-websocket') {
818828

819829
testImplementation project(':spring-integration-event')
820830
testImplementation "org.apache.tomcat.embed:tomcat-embed-websocket:$tomcatVersion"
831+
832+
testRuntimeOnly 'com.fasterxml.jackson.core:jackson-databind'
821833
}
822834
}
823835

spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.springframework.integration.handler.support.PayloadExpressionArgumentResolver;
5959
import org.springframework.integration.handler.support.PayloadsArgumentResolver;
6060
import org.springframework.integration.json.JsonNodeWrapperToJsonNodeConverter;
61+
import org.springframework.integration.json.JsonPathUtils;
6162
import org.springframework.integration.support.DefaultMessageBuilderFactory;
6263
import org.springframework.integration.support.NullAwarePayloadArgumentResolver;
6364
import org.springframework.integration.support.SmartLifecycleRoleController;
@@ -121,8 +122,7 @@ class DefaultConfiguringBeanFactoryPostProcessor
121122

122123
Class<?> jsonPathClass = null;
123124
try {
124-
jsonPathClass = ClassUtils.forName(IntegrationConfigUtils.BASE_PACKAGE + ".json.JsonPathUtils",
125-
ClassUtils.getDefaultClassLoader());
125+
jsonPathClass = ClassUtils.forName("com.jayway.jsonpath.JsonPath", ClassUtils.getDefaultClassLoader());
126126
}
127127
catch (@SuppressWarnings("unused") ClassNotFoundException e) {
128128
LOGGER.debug("The '#jsonPath' SpEL function cannot be registered: " +
@@ -406,7 +406,8 @@ private void jsonPath(int registryId) throws LinkageError {
406406
&& !this.beanFactory.containsBean(jsonPathBeanName)
407407
&& !REGISTRIES_PROCESSED.contains(registryId)) {
408408

409-
IntegrationConfigUtils.registerSpelFunctionBean(this.registry, jsonPathBeanName, JSON_PATH_CLASS, "evaluate");
409+
IntegrationConfigUtils.registerSpelFunctionBean(this.registry, jsonPathBeanName,
410+
JsonPathUtils.class, "evaluate");
410411
}
411412
}
412413

spring-integration-jmx/src/test/java/org/springframework/integration/jmx/configuration/EnableMBeanExportTests.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2020 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,8 +25,7 @@
2525
import javax.management.MalformedObjectNameException;
2626
import javax.management.ObjectName;
2727

28-
import org.junit.Test;
29-
import org.junit.runner.RunWith;
28+
import org.junit.jupiter.api.Test;
3029

3130
import org.springframework.beans.factory.BeanFactory;
3231
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,16 +43,14 @@
4443
import org.springframework.jmx.support.MBeanServerFactoryBean;
4544
import org.springframework.mock.env.MockEnvironment;
4645
import org.springframework.test.annotation.DirtiesContext;
47-
import org.springframework.test.context.ContextConfiguration;
48-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
46+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4947

5048
/**
5149
* @author Artem Bilan
5250
* @author Gary Russell
5351
* @since 4.0
5452
*/
55-
@ContextConfiguration(initializers = EnableMBeanExportTests.EnvironmentApplicationContextInitializer.class)
56-
@RunWith(SpringJUnit4ClassRunner.class)
53+
@SpringJUnitConfig(initializers = EnableMBeanExportTests.EnvironmentApplicationContextInitializer.class)
5754
@DirtiesContext
5855
public class EnableMBeanExportTests {
5956

@@ -72,6 +69,8 @@ public class EnableMBeanExportTests {
7269
@SuppressWarnings("unchecked")
7370
@Test
7471
public void testEnableMBeanExport() throws MalformedObjectNameException, ClassNotFoundException {
72+
assertThat(beanFactory.containsBean("jsonPath")).isFalse(); // GH-3541
73+
assertThat(beanFactory.containsBean("xPath")).isFalse(); // GH-3541
7574

7675
assertThat(this.exporter.getServer()).isSameAs(this.mBeanServer);
7776
String[] componentNamePatterns = TestUtils.getPropertyValue(this.exporter, "componentNamePatterns", String[].class);
@@ -103,11 +102,11 @@ public void testEnableMBeanExport() throws MalformedObjectNameException, ClassNo
103102

104103
@Configuration
105104
@EnableIntegration
106-
@EnableIntegrationMBeanExport(server = "#{mbeanServer}",
105+
@EnableIntegrationMBeanExport(
106+
server = "#{mbeanServer}",
107107
defaultDomain = "${managed.domain}",
108-
managedComponents = {"input", "${managed.component}"})
109-
@EnableIntegrationManagement(
110-
defaultLoggingEnabled = "false")
108+
managedComponents = { "input", "${managed.component}" })
109+
@EnableIntegrationManagement(defaultLoggingEnabled = "false")
111110
public static class ContextConfiguration {
112111

113112
@Bean

0 commit comments

Comments
 (0)