This is an automated email from the ASF dual-hosted git repository.
wy471x pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 04ae68f66a fix(examples): register common auto-configuration for
Spring Boot 3 (#7516)
04ae68f66a is described below
commit 04ae68f66a1af6a95ef215d6009b7dbaef4df975
Author: Sean-Walker0 <[email protected]>
AuthorDate: Sat Oct 10 21:52:46 2026 +0800
fix(examples): register common auto-configuration for Spring Boot 3 (#7516)
* fix(examples): register common auto-configuration for Spring Boot 3
The project pins Spring Boot 3.3.1, which no longer reads
EnableAutoConfiguration candidates from META-INF/spring.factories.
shenyu-examples-common registered InterceptorConfiguration only via
spring.factories, so example applications depending on the shared
module silently lost the @Log aspect support on Boot 3.
Add the Boot 3
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
registration (the legacy spring.factories entry is kept untouched for
older tooling) and a test asserting both registrations stay in sync
(red before the imports file existed, green after).
Fixes #7477
* test(examples): assert the Boot 3 registration loads the shared beans
Review follow-up: add an ApplicationContextRunner test proving
InterceptorConfiguration registers LogInterceptor when loaded as an
auto-configuration, switch the metadata drift test to classpath-based
resource reads, and drop the double-negative existence assertion.
---------
Co-authored-by: Sean-Walker0
<[email protected]>
---
shenyu-examples/shenyu-examples-common/pom.xml | 5 ++
...rk.boot.autoconfigure.AutoConfiguration.imports | 18 +++++
.../common/Boot3AutoConfigurationMetadataTest.java | 86 ++++++++++++++++++++++
3 files changed, 109 insertions(+)
diff --git a/shenyu-examples/shenyu-examples-common/pom.xml
b/shenyu-examples/shenyu-examples-common/pom.xml
index 8e4256f1e7..a2d89e8f4b 100644
--- a/shenyu-examples/shenyu-examples-common/pom.xml
+++ b/shenyu-examples/shenyu-examples-common/pom.xml
@@ -38,5 +38,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/shenyu-examples/shenyu-examples-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
b/shenyu-examples/shenyu-examples-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000000..d77d63eef2
--- /dev/null
+++
b/shenyu-examples/shenyu-examples-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shenyu.examples.common.aop.InterceptorConfiguration
diff --git
a/shenyu-examples/shenyu-examples-common/src/test/java/org/apache/shenyu/examples/common/Boot3AutoConfigurationMetadataTest.java
b/shenyu-examples/shenyu-examples-common/src/test/java/org/apache/shenyu/examples/common/Boot3AutoConfigurationMetadataTest.java
new file mode 100644
index 0000000000..55744bed5d
--- /dev/null
+++
b/shenyu-examples/shenyu-examples-common/src/test/java/org/apache/shenyu/examples/common/Boot3AutoConfigurationMetadataTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.shenyu.examples.common;
+
+import org.apache.shenyu.examples.common.aop.InterceptorConfiguration;
+import org.apache.shenyu.examples.common.aop.LogInterceptor;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Verifies the shared example configuration is registered in the Boot 3
+ * auto-configuration metadata (Boot 3.3 no longer reads
+ * EnableAutoConfiguration entries from spring.factories) and that the
+ * registration actually loads.
+ */
+public final class Boot3AutoConfigurationMetadataTest {
+
+ private final ApplicationContextRunner contextRunner = new
ApplicationContextRunner()
+
.withConfiguration(AutoConfigurations.of(InterceptorConfiguration.class));
+
+ @Test
+ public void configurationRegistersItsBeans() {
+ contextRunner.run(context -> {
+ assertNotNull(context.getBean(LogInterceptor.class),
"InterceptorConfiguration must register logInterceptor");
+ });
+ }
+
+ @Test
+ public void autoConfigurationImportsMatchSpringFactories() throws
IOException {
+ List<String> boot3Classes =
readConfigurationClasses("/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports");
+ List<String> boot2Classes =
readConfigurationClasses("/META-INF/spring.factories").stream()
+ .filter(line -> line.startsWith("org.apache.shenyu"))
+ .collect(Collectors.toList());
+
+ assertFalse(boot2Classes.isEmpty(), "spring.factories must declare the
shared configuration");
+ assertEquals(boot2Classes, boot3Classes,
+ "the Boot 3 AutoConfiguration.imports file must register the
same configuration classes");
+ }
+
+ private List<String> readConfigurationClasses(final String resource)
throws IOException {
+ InputStream stream = getClass().getResourceAsStream(resource);
+ assertNotNull(stream, resource + " is missing from the module
resources");
+ List<String> lines = new ArrayList<>();
+ try (BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))) {
+ String line = reader.readLine();
+ while (Objects.nonNull(line)) {
+ lines.add(line);
+ line = reader.readLine();
+ }
+ }
+ return lines.stream()
+ .map(String::trim)
+ .filter(line -> !line.isEmpty() && !line.startsWith("#"))
+ .collect(Collectors.toList());
+ }
+}