Skip to content

Commit 46b4d45

Browse files
committed
Merge branch '3.4.x'
Closes gh-44580
2 parents 162be96 + dafcef3 commit 46b4d45

File tree

189 files changed

+1717
-829
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+1717
-829
lines changed

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelectorTests.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ void combinedExclusionsAreApplied() {
166166
}
167167

168168
@Test
169+
@WithTestAutoConfigurationImportsResource
170+
@WithTestAutoConfigurationReplacementsResource
169171
void removedExclusionsAreApplied() {
170172
TestAutoConfigurationImportSelector importSelector = new TestAutoConfigurationImportSelector(
171173
TestAutoConfiguration.class);
@@ -234,7 +236,9 @@ void getExclusionFilterReuseFilters() {
234236
}
235237

236238
@Test
237-
void soringConsidersReplacements() {
239+
@WithTestAutoConfigurationImportsResource
240+
@WithTestAutoConfigurationReplacementsResource
241+
void sortingConsidersReplacements() {
238242
TestAutoConfigurationImportSelector importSelector = new TestAutoConfigurationImportSelector(
239243
TestAutoConfiguration.class);
240244
setupImportSelector(importSelector);
@@ -397,4 +401,28 @@ static class SeventhAutoConfiguration {
397401

398402
}
399403

404+
@Target(ElementType.METHOD)
405+
@Retention(RetentionPolicy.RUNTIME)
406+
@WithResource(
407+
name = "META-INF/spring/org.springframework.boot.autoconfigure.AutoConfigurationImportSelectorTests$TestAutoConfiguration.imports",
408+
content = """
409+
org.springframework.boot.autoconfigure.AutoConfigurationImportSelectorTests$AfterDeprecatedAutoConfiguration
410+
org.springframework.boot.autoconfigure.AutoConfigurationImportSelectorTests$ReplacementAutoConfiguration
411+
""")
412+
@interface WithTestAutoConfigurationImportsResource {
413+
414+
}
415+
416+
@Target(ElementType.METHOD)
417+
@Retention(RetentionPolicy.RUNTIME)
418+
@WithResource(
419+
name = "META-INF/spring/org.springframework.boot.autoconfigure.AutoConfigurationImportSelectorTests$TestAutoConfiguration.replacements",
420+
content = """
421+
org.springframework.boot.autoconfigure.AutoConfigurationImportSelectorTests$DeprecatedAutoConfiguration=\
422+
org.springframework.boot.autoconfigure.AutoConfigurationImportSelectorTests$ReplacementAutoConfiguration
423+
""")
424+
@interface WithTestAutoConfigurationReplacementsResource {
425+
426+
}
427+
400428
}

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -20,13 +20,21 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23+
import org.springframework.boot.testsupport.classpath.resources.WithResource;
24+
2325
import static org.assertj.core.api.Assertions.assertThat;
2426

2527
/**
2628
* Test for {@link AutoConfigurationMetadataLoader}.
2729
*
2830
* @author Phillip Webb
2931
*/
32+
@WithResource(name = "metadata.properties", content = """
33+
test=
34+
test.string=abc
35+
test.int=123
36+
test.set=a,b,b,c
37+
""")
3038
class AutoConfigurationMetadataLoaderTests {
3139

3240
@Test
@@ -90,8 +98,8 @@ void getWithDefaultWhenMissingShouldReturnDefault() {
9098
}
9199

92100
private AutoConfigurationMetadata load() {
93-
return AutoConfigurationMetadataLoader.loadMetadata(null,
94-
"META-INF/AutoConfigurationMetadataLoaderTests.properties");
101+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
102+
return AutoConfigurationMetadataLoader.loadMetadata(classLoader, "metadata.properties");
95103
}
96104

97105
}

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReplacementsTests.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -24,19 +24,33 @@
2424
import java.util.List;
2525
import java.util.Set;
2626

27+
import org.junit.jupiter.api.BeforeEach;
2728
import org.junit.jupiter.api.Test;
2829

30+
import org.springframework.boot.testsupport.classpath.resources.WithResource;
31+
2932
import static org.assertj.core.api.Assertions.assertThat;
3033

3134
/**
3235
* Tests for {@link AutoConfigurationReplacements}.
3336
*
3437
* @author Phillip Webb
3538
*/
39+
@WithResource(
40+
name = "META-INF/spring/org.springframework.boot.autoconfigure.AutoConfigurationReplacementsTests$TestAutoConfigurationReplacements.replacements",
41+
content = """
42+
com.example.A1=com.example.A2
43+
com.example.B1=com.example.B2
44+
""")
3645
class AutoConfigurationReplacementsTests {
3746

38-
private final AutoConfigurationReplacements replacements = AutoConfigurationReplacements
39-
.load(TestAutoConfigurationReplacements.class, null);
47+
private AutoConfigurationReplacements replacements;
48+
49+
@BeforeEach
50+
void loadReplacements() {
51+
this.replacements = AutoConfigurationReplacements.load(TestAutoConfigurationReplacements.class,
52+
Thread.currentThread().getContextClassLoader());
53+
}
4054

4155
@Test
4256
void replaceWhenMatchReplacesClassName() {

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3030
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
31+
import org.springframework.boot.testsupport.classpath.resources.WithResource;
3132
import org.springframework.core.annotation.AliasFor;
3233
import org.springframework.core.io.DefaultResourceLoader;
3334
import org.springframework.core.type.AnnotationMetadata;
@@ -74,6 +75,12 @@ void importsAreSelectedUsingClassesAttribute() throws Exception {
7475
}
7576

7677
@Test
78+
@WithResource(
79+
name = "META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFile.imports",
80+
content = """
81+
org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$ImportedAutoConfiguration
82+
org.springframework.boot.autoconfigure.missing.MissingAutoConfiguration
83+
""")
7784
void importsAreSelectedFromImportsFile() throws Exception {
7885
AnnotationMetadata annotationMetadata = getAnnotationMetadata(FromImportsFile.class);
7986
String[] imports = this.importSelector.selectImports(annotationMetadata);
@@ -83,9 +90,15 @@ void importsAreSelectedFromImportsFile() throws Exception {
8390
}
8491

8592
@Test
93+
@WithResource(
94+
name = "META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFile.imports",
95+
content = """
96+
optional:org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$ImportedAutoConfiguration
97+
optional:org.springframework.boot.autoconfigure.missing.MissingAutoConfiguration
98+
org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$AnotherImportedAutoConfiguration
99+
""")
86100
void importsSelectedFromImportsFileIgnoreMissingOptionalClasses() throws Exception {
87-
AnnotationMetadata annotationMetadata = getAnnotationMetadata(
88-
FromImportsFileIgnoresMissingOptionalClasses.class);
101+
AnnotationMetadata annotationMetadata = getAnnotationMetadata(FromImportsFile.class);
89102
String[] imports = this.importSelector.selectImports(annotationMetadata);
90103
assertThat(imports).containsExactly(
91104
"org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$ImportedAutoConfiguration",

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -910,9 +910,8 @@ void enableSslWithInvalidTrustStoreTypeShouldFail() {
910910
void enableSslWithBundle() {
911911
this.contextRunner.withUserConfiguration(TestConfiguration.class)
912912
.withPropertyValues("spring.rabbitmq.ssl.bundle=test-bundle",
913-
"spring.ssl.bundle.jks.test-bundle.keystore.location=classpath:test.jks",
914-
"spring.ssl.bundle.jks.test-bundle.keystore.password=secret",
915-
"spring.ssl.bundle.jks.test-bundle.key.password=password")
913+
"spring.ssl.bundle.jks.test-bundle.keystore.location=classpath:org/springframework/boot/autoconfigure/amqp/test.jks",
914+
"spring.ssl.bundle.jks.test-bundle.keystore.password=secret")
916915
.run((context) -> {
917916
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context);
918917
assertThat(rabbitConnectionFactory.isSSL()).isTrue();

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
import org.springframework.boot.test.context.FilteredClassLoader;
7373
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
7474
import org.springframework.boot.test.system.OutputCaptureExtension;
75+
import org.springframework.boot.testsupport.classpath.resources.WithPackageResources;
76+
import org.springframework.boot.testsupport.classpath.resources.WithResource;
7577
import org.springframework.context.ApplicationContext;
7678
import org.springframework.context.annotation.Bean;
7779
import org.springframework.context.annotation.Configuration;
@@ -288,13 +290,13 @@ void testUsingJpa() {
288290
}
289291

290292
@Test
293+
@WithPackageResources("custom-schema.sql")
291294
void testRenamePrefix() {
292295
this.contextRunner
293296
.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class,
294297
HibernateJpaAutoConfiguration.class)
295298
.withPropertyValues("spring.datasource.generate-unique-name=true",
296-
"spring.batch.jdbc.schema:classpath:batch/custom-schema.sql",
297-
"spring.batch.jdbc.tablePrefix:PREFIX_")
299+
"spring.batch.jdbc.schema:classpath:custom-schema.sql", "spring.batch.jdbc.tablePrefix:PREFIX_")
298300
.run((context) -> {
299301
assertThat(context).hasSingleBean(JobLauncher.class);
300302
assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema())
@@ -412,6 +414,7 @@ void jobRepositoryBeansDependOnFlyway() {
412414
}
413415

414416
@Test
417+
@WithResource(name = "db/changelog/db.changelog-master.yaml", content = "databaseChangeLog:")
415418
void jobRepositoryBeansDependOnLiquibase() {
416419
this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class)
417420
.withUserConfiguration(LiquibaseAutoConfiguration.class)

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -34,6 +34,7 @@
3434
import org.springframework.boot.sql.init.DatabaseInitializationMode;
3535
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3636
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
37+
import org.springframework.boot.testsupport.classpath.resources.WithPackageResources;
3738
import org.springframework.jdbc.core.JdbcTemplate;
3839
import org.springframework.transaction.annotation.Isolation;
3940

@@ -70,11 +71,11 @@ void jdbcWithDefaultSettings() {
7071
}
7172

7273
@Test
74+
@WithPackageResources("custom-schema.sql")
7375
void jdbcWithCustomPrefix() {
7476
this.contextRunner.withUserConfiguration(DefaultConfiguration.class, EmbeddedDataSourceConfiguration.class)
7577
.withPropertyValues("spring.datasource.generate-unique-name=true",
76-
"spring.batch.jdbc.schema:classpath:batch/custom-schema.sql",
77-
"spring.batch.jdbc.tablePrefix:PREFIX_")
78+
"spring.batch.jdbc.schema:classpath:custom-schema.sql", "spring.batch.jdbc.tablePrefix:PREFIX_")
7879
.run((context) -> {
7980
assertThat(new JdbcTemplate(context.getBean(DataSource.class))
8081
.queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java

+73-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package org.springframework.boot.autoconfigure.cache;
1818

19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
1923
import java.util.ArrayList;
2024
import java.util.Collections;
2125
import java.util.List;
@@ -48,6 +52,7 @@
4852
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
4953
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
5054
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
55+
import org.springframework.boot.testsupport.classpath.resources.WithResource;
5156
import org.springframework.cache.Cache;
5257
import org.springframework.cache.Cache.ValueWrapper;
5358
import org.springframework.cache.CacheManager;
@@ -481,6 +486,7 @@ void jCacheCacheWithPropertiesCustomizer() {
481486
}
482487

483488
@Test
489+
@WithHazelcastXmlResource
484490
void hazelcastCacheExplicit() {
485491
this.contextRunner.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class))
486492
.withUserConfiguration(DefaultCacheConfiguration.class)
@@ -496,6 +502,7 @@ void hazelcastCacheExplicit() {
496502
}
497503

498504
@Test
505+
@WithHazelcastXmlResource
499506
void hazelcastCacheWithCustomizers() {
500507
this.contextRunner.withUserConfiguration(HazelcastCacheAndCustomizersConfiguration.class)
501508
.withPropertyValues("spring.cache.type=hazelcast")
@@ -548,10 +555,31 @@ void hazelcastAsJCacheWithCaches() {
548555
}
549556

550557
@Test
558+
@WithResource(name = "hazelcast-specific.xml", content = """
559+
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-5.0.xsd"
560+
xmlns="http://www.hazelcast.com/schema/config"
561+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
562+
563+
<queue name="foobar"/>
564+
565+
<map name="foobar">
566+
<time-to-live-seconds>3600</time-to-live-seconds>
567+
<max-idle-seconds>600</max-idle-seconds>
568+
</map>
569+
570+
<network>
571+
<join>
572+
<auto-detection enabled="false" />
573+
<multicast enabled="false"/>
574+
</join>
575+
</network>
576+
577+
</hazelcast>
578+
""")
551579
void hazelcastAsJCacheWithConfig() {
552580
String cachingProviderFqn = HazelcastServerCachingProvider.class.getName();
553581
try {
554-
String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
582+
String configLocation = "hazelcast-specific.xml";
555583
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
556584
.withPropertyValues("spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn,
557585
"spring.cache.jcache.config=" + configLocation)
@@ -568,6 +596,7 @@ void hazelcastAsJCacheWithConfig() {
568596
}
569597

570598
@Test
599+
@WithHazelcastXmlResource
571600
void hazelcastAsJCacheWithExistingHazelcastInstance() {
572601
String cachingProviderFqn = HazelcastServerCachingProvider.class.getName();
573602
this.contextRunner.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class))
@@ -587,6 +616,7 @@ void hazelcastAsJCacheWithExistingHazelcastInstance() {
587616
}
588617

589618
@Test
619+
@WithInfinispanXmlResource
590620
void infinispanCacheWithConfig() {
591621
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
592622
.withPropertyValues("spring.cache.type=infinispan", "spring.cache.infinispan.config=infinispan.xml")
@@ -635,6 +665,7 @@ void infinispanAsJCacheWithCaches() {
635665
}
636666

637667
@Test
668+
@WithInfinispanXmlResource
638669
void infinispanAsJCacheWithConfig() {
639670
String cachingProviderClassName = JCachingProvider.class.getName();
640671
String configLocation = "infinispan.xml";
@@ -1078,4 +1109,45 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
10781109

10791110
}
10801111

1112+
@Target(ElementType.METHOD)
1113+
@Retention(RetentionPolicy.RUNTIME)
1114+
@WithResource(name = "infinispan.xml", content = """
1115+
<?xml version="1.0" encoding="UTF-8"?>
1116+
<infinispan>
1117+
1118+
<!-- ************************************** -->
1119+
<!-- Corresponds to @Cacheable("cache-name") -->
1120+
<!-- ************************************** -->
1121+
<cache-container default-cache="default">
1122+
<local-cache name="default"/>
1123+
<local-cache name="foo"/>
1124+
<local-cache name="bar" />
1125+
</cache-container>
1126+
1127+
</infinispan>
1128+
""")
1129+
@interface WithInfinispanXmlResource {
1130+
1131+
}
1132+
1133+
@Target(ElementType.METHOD)
1134+
@Retention(RetentionPolicy.RUNTIME)
1135+
@WithResource(name = "hazelcast.xml", content = """
1136+
<hazelcast
1137+
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-5.0.xsd"
1138+
xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1139+
<instance-name>default-instance</instance-name>
1140+
<map name="defaultCache" />
1141+
<network>
1142+
<join>
1143+
<auto-detection enabled="false" />
1144+
<multicast enabled="false" />
1145+
</join>
1146+
</network>
1147+
</hazelcast>
1148+
""")
1149+
@interface WithHazelcastXmlResource {
1150+
1151+
}
1152+
10811153
}

0 commit comments

Comments
 (0)