Create spring-boot-h2console module

This commit is contained in:
Moritz Halbritter 2025-03-25 14:27:08 +01:00 committed by Phillip Webb
parent 68c1d45ea8
commit d2a1dcbc8e
14 changed files with 52 additions and 21 deletions

View File

@ -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"

View File

@ -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")

View File

@ -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<H2ConsoleProperties> {
public static final class H2ConsoleRequestMatcher extends ApplicationContextRequestMatcher<ApplicationContext> {
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> h2ConsoleProperties) {
this.delegate = PathPatternRequestMatcher.withDefaults()
.matcher(h2ConsoleProperties.get().getPath() + "/**");
protected void initialized(Supplier<ApplicationContext> 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<H2ConsoleProperties> context) {
protected boolean matches(HttpServletRequest request, Supplier<ApplicationContext> context) {
return this.delegate.matches(request);
}

View File

@ -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

View File

@ -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;

View File

@ -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",

View File

@ -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"))

View File

@ -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")
}

View File

@ -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")

View File

@ -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 {

View File

@ -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;

View File

@ -0,0 +1 @@
org.springframework.boot.h2console.autoconfigure.H2ConsoleAutoConfiguration

View File

@ -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;

View File

@ -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;