Skip to content

Commit be12093

Browse files
committed
Create spring-boot-h2 module
1 parent fed2f4f commit be12093

File tree

14 files changed

+55
-22
lines changed

14 files changed

+55
-22
lines changed

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ include "spring-boot-project:spring-boot-flyway"
6363
include "spring-boot-project:spring-boot-freemarker"
6464
include "spring-boot-project:spring-boot-groovy-templates"
6565
include "spring-boot-project:spring-boot-gson"
66+
include "spring-boot-project:spring-boot-h2"
6667
include "spring-boot-project:spring-boot-hazelcast"
6768
include "spring-boot-project:spring-boot-integration"
6869
include "spring-boot-project:spring-boot-jackson"

spring-boot-project/spring-boot-autoconfigure-all/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dependencies {
4848
optional(project(":spring-boot-project:spring-boot-data-jpa"))
4949
optional(project(":spring-boot-project:spring-boot-elasticsearch"))
5050
optional(project(":spring-boot-project:spring-boot-flyway"))
51+
optional(project(":spring-boot-project:spring-boot-h2"))
5152
optional(project(":spring-boot-project:spring-boot-hazelcast"))
5253
optional(project(":spring-boot-project:spring-boot-jackson"))
5354
optional(project(":spring-boot-project:spring-boot-jdbc"))
@@ -70,7 +71,6 @@ dependencies {
7071
optional("com.fasterxml.jackson.module:jackson-module-jakarta-xmlbind-annotations")
7172
optional("com.fasterxml.jackson.module:jackson-module-parameter-names")
7273
optional("com.hazelcast:hazelcast-spring")
73-
optional("com.h2database:h2")
7474
optional("com.nimbusds:oauth2-oidc-sdk")
7575
optional("com.oracle.database.jdbc:ojdbc11")
7676
optional("com.oracle.database.jdbc:ucp11")

spring-boot-project/spring-boot-autoconfigure-all/src/main/java/org/springframework/boot/autoconfigure/security/servlet/PathRequest.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 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,12 +20,14 @@
2020

2121
import jakarta.servlet.http.HttpServletRequest;
2222

23-
import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties;
2423
import org.springframework.boot.autoconfigure.security.StaticResourceLocation;
24+
import org.springframework.boot.h2.autoconfigure.H2ConsoleProperties;
2525
import org.springframework.boot.security.servlet.ApplicationContextRequestMatcher;
2626
import org.springframework.boot.web.context.WebServerApplicationContext;
27+
import org.springframework.context.ApplicationContext;
2728
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
2829
import org.springframework.security.web.util.matcher.RequestMatcher;
30+
import org.springframework.util.Assert;
2931
import org.springframework.web.context.WebApplicationContext;
3032

3133
/**
@@ -63,12 +65,12 @@ public static H2ConsoleRequestMatcher toH2Console() {
6365
/**
6466
* The request matcher used to match against h2 console path.
6567
*/
66-
public static final class H2ConsoleRequestMatcher extends ApplicationContextRequestMatcher<H2ConsoleProperties> {
68+
public static final class H2ConsoleRequestMatcher extends ApplicationContextRequestMatcher<ApplicationContext> {
6769

6870
private volatile RequestMatcher delegate;
6971

7072
private H2ConsoleRequestMatcher() {
71-
super(H2ConsoleProperties.class);
73+
super(ApplicationContext.class);
7274
}
7375

7476
@Override
@@ -77,12 +79,15 @@ protected boolean ignoreApplicationContext(WebApplicationContext applicationCont
7779
}
7880

7981
@Override
80-
protected void initialized(Supplier<H2ConsoleProperties> h2ConsoleProperties) {
81-
this.delegate = new AntPathRequestMatcher(h2ConsoleProperties.get().getPath() + "/**");
82+
protected void initialized(Supplier<ApplicationContext> context) {
83+
H2ConsoleProperties properties = context.get().getBean(H2ConsoleProperties.class);
84+
String path = properties.getPath();
85+
Assert.hasText(path, "'path' in H2ConsoleProperties must not be empty");
86+
this.delegate = new AntPathRequestMatcher(path + "/**");
8287
}
8388

8489
@Override
85-
protected boolean matches(HttpServletRequest request, Supplier<H2ConsoleProperties> context) {
90+
protected boolean matches(HttpServletRequest request, Supplier<ApplicationContext> context) {
8691
return this.delegate.matches(request);
8792
}
8893

spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ org.springframework.boot.autoconfigure.graphql.rsocket.RSocketGraphQlClientAutoC
3939
org.springframework.boot.autoconfigure.graphql.security.GraphQlWebFluxSecurityAutoConfiguration
4040
org.springframework.boot.autoconfigure.graphql.security.GraphQlWebMvcSecurityAutoConfiguration
4141
org.springframework.boot.autoconfigure.graphql.servlet.GraphQlWebMvcAutoConfiguration
42-
org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration
4342
org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration
4443
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration
4544
org.springframework.boot.autoconfigure.http.client.HttpClientAutoConfiguration

spring-boot-project/spring-boot-autoconfigure-all/src/test/java/org/springframework/boot/autoconfigure/security/servlet/PathRequestTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 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,8 +20,8 @@
2020
import org.assertj.core.api.AssertDelegateTarget;
2121
import org.junit.jupiter.api.Test;
2222

23-
import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties;
2423
import org.springframework.boot.autoconfigure.web.ServerProperties;
24+
import org.springframework.boot.h2.autoconfigure.H2ConsoleProperties;
2525
import org.springframework.mock.web.MockHttpServletRequest;
2626
import org.springframework.mock.web.MockServletContext;
2727
import org.springframework.security.web.util.matcher.RequestMatcher;

spring-boot-project/spring-boot-dependencies/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,7 @@ bom {
20402040
"spring-boot-freemarker",
20412041
"spring-boot-groovy-templates",
20422042
"spring-boot-gson",
2043+
"spring-boot-h2",
20432044
"spring-boot-hazelcast",
20442045
"spring-boot-integration",
20452046
"spring-boot-jackson",

spring-boot-project/spring-boot-docs/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ dependencies {
6666
autoConfiguration(project(path: ":spring-boot-project:spring-boot-flyway", configuration: "autoConfigurationMetadata"))
6767
autoConfiguration(project(path: ":spring-boot-project:spring-boot-freemarker", configuration: "autoConfigurationMetadata"))
6868
autoConfiguration(project(path: ":spring-boot-project:spring-boot-gson", configuration: "autoConfigurationMetadata"))
69+
autoConfiguration(project(path: ":spring-boot-project:spring-boot-h2", configuration: "autoConfigurationMetadata"))
6970
autoConfiguration(project(path: ":spring-boot-project:spring-boot-hazelcast", configuration: "autoConfigurationMetadata"))
7071
autoConfiguration(project(path: ":spring-boot-project:spring-boot-integration", configuration: "autoConfigurationMetadata"))
7172
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "autoConfigurationMetadata"))
@@ -113,6 +114,7 @@ dependencies {
113114
configurationProperties(project(path: ":spring-boot-project:spring-boot-flyway", configuration: "configurationPropertiesMetadata"))
114115
configurationProperties(project(path: ":spring-boot-project:spring-boot-freemarker", configuration: "configurationPropertiesMetadata"))
115116
configurationProperties(project(path: ":spring-boot-project:spring-boot-gson", configuration: "configurationPropertiesMetadata"))
117+
configurationProperties(project(path: ":spring-boot-project:spring-boot-h2", configuration: "configurationPropertiesMetadata"))
116118
configurationProperties(project(path: ":spring-boot-project:spring-boot-hazelcast", configuration: "configurationPropertiesMetadata"))
117119
configurationProperties(project(path: ":spring-boot-project:spring-boot-integration", configuration: "configurationPropertiesMetadata"))
118120
configurationProperties(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "configurationPropertiesMetadata"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
id "java-library"
3+
id "org.springframework.boot.auto-configuration"
4+
id "org.springframework.boot.configuration-properties"
5+
id "org.springframework.boot.deployed"
6+
id "org.springframework.boot.optional-dependencies"
7+
}
8+
9+
description = "Spring Boot H2"
10+
11+
dependencies {
12+
api(project(":spring-boot-project:spring-boot"))
13+
api("jakarta.servlet:jakarta.servlet-api")
14+
api("com.h2database:h2")
15+
16+
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
17+
18+
testImplementation(project(":spring-boot-project:spring-boot-test"))
19+
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
20+
testImplementation(project(":spring-boot-project:spring-boot-jdbc"))
21+
testImplementation(project(":spring-boot-project:spring-boot-tomcat"))
22+
testImplementation("org.springframework:spring-web")
23+
24+
testRuntimeOnly("ch.qos.logback:logback-classic")
25+
}
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.h2;
17+
package org.springframework.boot.h2.autoconfigure;
1818

1919
import java.sql.Connection;
2020
import java.util.List;
@@ -33,9 +33,8 @@
3333
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3434
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
3535
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
36-
import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties.Settings;
3736
import org.springframework.boot.context.properties.EnableConfigurationProperties;
38-
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
37+
import org.springframework.boot.h2.autoconfigure.H2ConsoleProperties.Settings;
3938
import org.springframework.boot.web.servlet.ServletRegistrationBean;
4039
import org.springframework.context.annotation.Bean;
4140
import org.springframework.core.log.LogMessage;
@@ -47,9 +46,9 @@
4746
* @author Marten Deinum
4847
* @author Stephane Nicoll
4948
* @author Phillip Webb
50-
* @since 1.3.0
49+
* @since 4.0.0
5150
*/
52-
@AutoConfiguration(after = DataSourceAutoConfiguration.class)
51+
@AutoConfiguration
5352
@ConditionalOnWebApplication(type = Type.SERVLET)
5453
@ConditionalOnClass(JakartaWebServlet.class)
5554
@ConditionalOnBooleanProperty("spring.h2.console.enabled")
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.h2;
17+
package org.springframework.boot.h2.autoconfigure;
1818

1919
import org.springframework.boot.context.properties.ConfigurationProperties;
2020
import org.springframework.util.Assert;
@@ -25,7 +25,7 @@
2525
* @author Andy Wilkinson
2626
* @author Marten Deinum
2727
* @author Stephane Nicoll
28-
* @since 1.3.0
28+
* @since 4.0.0
2929
*/
3030
@ConfigurationProperties("spring.h2.console")
3131
public class H2ConsoleProperties {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 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.
@@ -17,4 +17,4 @@
1717
/**
1818
* Auto-configuration for H2's Console.
1919
*/
20-
package org.springframework.boot.autoconfigure.h2;
20+
package org.springframework.boot.h2.autoconfigure;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.boot.h2.autoconfigure.H2ConsoleAutoConfiguration
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.h2;
17+
package org.springframework.boot.h2.autoconfigure;
1818

1919
import java.net.URL;
2020
import java.net.URLClassLoader;
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.h2;
17+
package org.springframework.boot.h2.autoconfigure;
1818

1919
import org.junit.jupiter.api.Test;
2020

0 commit comments

Comments
 (0)