diff --git a/settings.gradle b/settings.gradle index b55c4201248..7660814c3f6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -63,6 +63,7 @@ include "spring-boot-project:spring-boot-flyway" include "spring-boot-project:spring-boot-freemarker" include "spring-boot-project:spring-boot-groovy-templates" include "spring-boot-project:spring-boot-gson" +include "spring-boot-project:spring-boot-h2console" include "spring-boot-project:spring-boot-hazelcast" include "spring-boot-project:spring-boot-integration" include "spring-boot-project:spring-boot-jackson" diff --git a/spring-boot-project/spring-boot-autoconfigure-all/build.gradle b/spring-boot-project/spring-boot-autoconfigure-all/build.gradle index abddfc6dba2..4c2080836ac 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/build.gradle +++ b/spring-boot-project/spring-boot-autoconfigure-all/build.gradle @@ -48,6 +48,7 @@ dependencies { optional(project(":spring-boot-project:spring-boot-data-jpa")) optional(project(":spring-boot-project:spring-boot-elasticsearch")) optional(project(":spring-boot-project:spring-boot-flyway")) + optional(project(":spring-boot-project:spring-boot-h2console")) optional(project(":spring-boot-project:spring-boot-hazelcast")) optional(project(":spring-boot-project:spring-boot-jackson")) optional(project(":spring-boot-project:spring-boot-jdbc")) @@ -70,7 +71,6 @@ dependencies { optional("com.fasterxml.jackson.module:jackson-module-jakarta-xmlbind-annotations") optional("com.fasterxml.jackson.module:jackson-module-parameter-names") optional("com.hazelcast:hazelcast-spring") - optional("com.h2database:h2") optional("com.nimbusds:oauth2-oidc-sdk") optional("com.oracle.database.jdbc:ojdbc11") optional("com.oracle.database.jdbc:ucp11") diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/security/servlet/PathRequest.java b/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/security/servlet/PathRequest.java index 438befcd631..8124babfaa4 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/security/servlet/PathRequest.java +++ b/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/security/servlet/PathRequest.java @@ -20,12 +20,14 @@ import java.util.function.Supplier; import jakarta.servlet.http.HttpServletRequest; -import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties; import org.springframework.boot.autoconfigure.security.StaticResourceLocation; +import org.springframework.boot.h2console.autoconfigure.H2ConsoleProperties; import org.springframework.boot.security.servlet.ApplicationContextRequestMatcher; import org.springframework.boot.web.context.WebServerApplicationContext; +import org.springframework.context.ApplicationContext; import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.util.Assert; import org.springframework.web.context.WebApplicationContext; /** @@ -63,12 +65,12 @@ public final class PathRequest { /** * The request matcher used to match against h2 console path. */ - public static final class H2ConsoleRequestMatcher extends ApplicationContextRequestMatcher { + public static final class H2ConsoleRequestMatcher extends ApplicationContextRequestMatcher { private volatile RequestMatcher delegate; private H2ConsoleRequestMatcher() { - super(H2ConsoleProperties.class); + super(ApplicationContext.class); } @Override @@ -77,13 +79,14 @@ public final class PathRequest { } @Override - protected void initialized(Supplier h2ConsoleProperties) { - this.delegate = PathPatternRequestMatcher.withDefaults() - .matcher(h2ConsoleProperties.get().getPath() + "/**"); + protected void initialized(Supplier context) { + String path = context.get().getBean(H2ConsoleProperties.class).getPath(); + Assert.hasText(path, "'path' in H2ConsoleProperties must not be empty"); + this.delegate = PathPatternRequestMatcher.withDefaults().matcher(path + "/**"); } @Override - protected boolean matches(HttpServletRequest request, Supplier context) { + protected boolean matches(HttpServletRequest request, Supplier context) { return this.delegate.matches(request); } diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 8a07b489fa9..01382ccf0d6 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -39,7 +39,6 @@ org.springframework.boot.autoconfigure.graphql.rsocket.RSocketGraphQlClientAutoC org.springframework.boot.autoconfigure.graphql.security.GraphQlWebFluxSecurityAutoConfiguration org.springframework.boot.autoconfigure.graphql.security.GraphQlWebMvcSecurityAutoConfiguration org.springframework.boot.autoconfigure.graphql.servlet.GraphQlWebMvcAutoConfiguration -org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration org.springframework.boot.autoconfigure.http.client.HttpClientAutoConfiguration diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/security/servlet/PathRequestTests.java b/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/security/servlet/PathRequestTests.java index b5c07801b46..28b2b0bd488 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/security/servlet/PathRequestTests.java +++ b/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/security/servlet/PathRequestTests.java @@ -20,8 +20,8 @@ import jakarta.servlet.http.HttpServletRequest; import org.assertj.core.api.AssertDelegateTarget; import org.junit.jupiter.api.Test; -import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties; import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.h2console.autoconfigure.H2ConsoleProperties; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockServletContext; import org.springframework.security.web.util.matcher.RequestMatcher; diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index ae978b3b1d8..246cd7bca62 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -2034,6 +2034,7 @@ bom { "spring-boot-freemarker", "spring-boot-groovy-templates", "spring-boot-gson", + "spring-boot-h2console", "spring-boot-hazelcast", "spring-boot-integration", "spring-boot-jackson", diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index 9b1bb5bb536..38c73c5edb6 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -69,6 +69,7 @@ dependencies { autoConfiguration(project(path: ":spring-boot-project:spring-boot-flyway", configuration: "autoConfigurationMetadata")) autoConfiguration(project(path: ":spring-boot-project:spring-boot-freemarker", configuration: "autoConfigurationMetadata")) autoConfiguration(project(path: ":spring-boot-project:spring-boot-gson", configuration: "autoConfigurationMetadata")) + autoConfiguration(project(path: ":spring-boot-project:spring-boot-h2console", configuration: "autoConfigurationMetadata")) autoConfiguration(project(path: ":spring-boot-project:spring-boot-hazelcast", configuration: "autoConfigurationMetadata")) autoConfiguration(project(path: ":spring-boot-project:spring-boot-integration", configuration: "autoConfigurationMetadata")) autoConfiguration(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "autoConfigurationMetadata")) @@ -116,6 +117,7 @@ dependencies { configurationProperties(project(path: ":spring-boot-project:spring-boot-flyway", configuration: "configurationPropertiesMetadata")) configurationProperties(project(path: ":spring-boot-project:spring-boot-freemarker", configuration: "configurationPropertiesMetadata")) configurationProperties(project(path: ":spring-boot-project:spring-boot-gson", configuration: "configurationPropertiesMetadata")) + configurationProperties(project(path: ":spring-boot-project:spring-boot-h2console", configuration: "configurationPropertiesMetadata")) configurationProperties(project(path: ":spring-boot-project:spring-boot-hazelcast", configuration: "configurationPropertiesMetadata")) configurationProperties(project(path: ":spring-boot-project:spring-boot-integration", configuration: "configurationPropertiesMetadata")) configurationProperties(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "configurationPropertiesMetadata")) diff --git a/spring-boot-project/spring-boot-h2console/build.gradle b/spring-boot-project/spring-boot-h2console/build.gradle new file mode 100644 index 00000000000..fb4c02d9f0b --- /dev/null +++ b/spring-boot-project/spring-boot-h2console/build.gradle @@ -0,0 +1,25 @@ +plugins { + id "java-library" + id "org.springframework.boot.auto-configuration" + id "org.springframework.boot.configuration-properties" + id "org.springframework.boot.deployed" + id "org.springframework.boot.optional-dependencies" +} + +description = "Spring Boot H2" + +dependencies { + api(project(":spring-boot-project:spring-boot")) + api("jakarta.servlet:jakarta.servlet-api") + api("com.h2database:h2") + + optional(project(":spring-boot-project:spring-boot-autoconfigure")) + + testImplementation(project(":spring-boot-project:spring-boot-test")) + testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) + testImplementation(project(":spring-boot-project:spring-boot-jdbc")) + testImplementation(project(":spring-boot-project:spring-boot-tomcat")) + testImplementation("org.springframework:spring-web") + + testRuntimeOnly("ch.qos.logback:logback-classic") +} diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java b/spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfiguration.java similarity index 94% rename from spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java rename to spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfiguration.java index 63438e7e0ba..e4cfeebf2a8 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java +++ b/spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.h2; +package org.springframework.boot.h2console.autoconfigure; import java.sql.Connection; import java.util.List; @@ -33,9 +33,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProp import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; -import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties.Settings; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration; +import org.springframework.boot.h2console.autoconfigure.H2ConsoleProperties.Settings; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.core.log.LogMessage; @@ -47,9 +46,9 @@ import org.springframework.core.log.LogMessage; * @author Marten Deinum * @author Stephane Nicoll * @author Phillip Webb - * @since 1.3.0 + * @since 4.0.0 */ -@AutoConfiguration(after = DataSourceAutoConfiguration.class) +@AutoConfiguration @ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnClass(JakartaWebServlet.class) @ConditionalOnBooleanProperty("spring.h2.console.enabled") diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java b/spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleProperties.java similarity index 97% rename from spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java rename to spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleProperties.java index 1f420eef95e..c625529d29d 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java +++ b/spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleProperties.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.h2; +package org.springframework.boot.h2console.autoconfigure; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.util.Assert; @@ -25,7 +25,7 @@ import org.springframework.util.Assert; * @author Andy Wilkinson * @author Marten Deinum * @author Stephane Nicoll - * @since 1.3.0 + * @since 4.0.0 */ @ConfigurationProperties("spring.h2.console") public class H2ConsoleProperties { diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/package-info.java b/spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/package-info.java similarity index 84% rename from spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/package-info.java rename to spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/package-info.java index 23dc367447c..1c5d3821e77 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/h2/package-info.java +++ b/spring-boot-project/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,4 +17,4 @@ /** * Auto-configuration for H2's Console. */ -package org.springframework.boot.autoconfigure.h2; +package org.springframework.boot.h2console.autoconfigure; diff --git a/spring-boot-project/spring-boot-h2console/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-h2console/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000000..9856b070c6f --- /dev/null +++ b/spring-boot-project/spring-boot-h2console/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.springframework.boot.h2console.autoconfigure.H2ConsoleAutoConfiguration diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java b/spring-boot-project/spring-boot-h2console/src/test/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfigurationTests.java similarity index 99% rename from spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java rename to spring-boot-project/spring-boot-h2console/src/test/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfigurationTests.java index 1e7ababaaac..13843b268a7 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-h2console/src/test/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfigurationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.h2; +package org.springframework.boot.h2console.autoconfigure; import java.net.URL; import java.net.URLClassLoader; diff --git a/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsolePropertiesTests.java b/spring-boot-project/spring-boot-h2console/src/test/java/org/springframework/boot/h2console/autoconfigure/H2ConsolePropertiesTests.java similarity index 96% rename from spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsolePropertiesTests.java rename to spring-boot-project/spring-boot-h2console/src/test/java/org/springframework/boot/h2console/autoconfigure/H2ConsolePropertiesTests.java index bebfd11bf91..d25e5abba2a 100644 --- a/spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsolePropertiesTests.java +++ b/spring-boot-project/spring-boot-h2console/src/test/java/org/springframework/boot/h2console/autoconfigure/H2ConsolePropertiesTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.h2; +package org.springframework.boot.h2console.autoconfigure; import org.junit.jupiter.api.Test;