Skip to content

Commit 0f5a039

Browse files
committed
Update to Spring Boot 4.0.0-RC1
This commit updates testjars to support Spring Boot 4.0.x. Resolves #98 Signed-off-by: Chris Bono <[email protected]>
1 parent 734cb20 commit 0f5a039

File tree

9 files changed

+33
-39
lines changed

9 files changed

+33
-39
lines changed

samples/oauth2-login-custom-config/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.4.0'
4-
id 'io.spring.dependency-management' version '1.1.2'
3+
id 'org.springframework.boot' version '4.0.0-RC1'
4+
id 'io.spring.dependency-management' version '1.1.7'
55
}
66

77
group = 'com.example'
@@ -22,6 +22,7 @@ dependencies {
2222
testImplementation project(':spring-boot-testjars-maven')
2323
testImplementation 'org.springframework.boot:spring-boot-starter-test'
2424
testImplementation 'org.springframework.boot:spring-boot-starter-oauth2-authorization-server'
25+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
2526
}
2627

2728
tasks.named('test') {

samples/oauth2-login-custom-config/src/test/java/testjars/authorizationserver/SecurityConfig.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.springframework.security.config.Customizer;
2929
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
3030
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
31+
import org.springframework.security.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration;
32+
import org.springframework.security.config.annotation.web.configurers.oauth2.server.authorization.OAuth2AuthorizationServerConfigurer;
3133
import org.springframework.security.core.userdetails.User;
3234
import org.springframework.security.core.userdetails.UserDetails;
3335
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -38,8 +40,6 @@
3840
import org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository;
3941
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
4042
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
41-
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration;
42-
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer;
4343
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
4444
import org.springframework.security.oauth2.server.authorization.settings.ClientSettings;
4545
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@@ -59,9 +59,14 @@ public class SecurityConfig {
5959

6060
@Bean
6161
@Order(1)
62-
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http)
63-
throws Exception {
64-
OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
62+
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) {
63+
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = new OAuth2AuthorizationServerConfigurer();
64+
http
65+
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
66+
.with(authorizationServerConfigurer, Customizer.withDefaults())
67+
.authorizeHttpRequests((authorize) ->
68+
authorize.anyRequest().authenticated()
69+
);
6570
http.getConfigurer(OAuth2AuthorizationServerConfigurer.class)
6671
.oidc(Customizer.withDefaults()); // Enable OpenID Connect 1.0
6772
http
@@ -82,8 +87,7 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
8287

8388
@Bean
8489
@Order(2)
85-
public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http)
86-
throws Exception {
90+
public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) {
8791
http
8892
.authorizeHttpRequests((authorize) -> authorize
8993
.anyRequest().authenticated()
@@ -96,6 +100,7 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http)
96100
return http.build();
97101
}
98102

103+
@SuppressWarnings("deprecation")
99104
@Bean
100105
public UserDetailsService userDetailsService() {
101106
UserDetails userDetails = User.withDefaultPasswordEncoder()

samples/oauth2-login/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '3.4.0'
4-
id 'io.spring.dependency-management' version '1.1.2'
3+
id 'org.springframework.boot' version '4.0.0-RC1'
4+
id 'io.spring.dependency-management' version '1.1.7'
55
}
66

77
group = 'com.example'
@@ -21,6 +21,7 @@ dependencies {
2121
testImplementation project(':spring-boot-testjars')
2222
testImplementation project(':spring-boot-testjars-maven')
2323
testImplementation 'org.springframework.boot:spring-boot-starter-test'
24+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
2425
}
2526

2627
tasks.named('test') {

spring-boot-testjars-maven/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ checkstyle {
2828
dependencies {
2929
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.40")
3030
api project(':spring-boot-testjars')
31-
api platform('org.springframework.boot:spring-boot-dependencies:3.4.0')
31+
api platform('org.springframework.boot:spring-boot-dependencies:4.0.0-RC1')
3232
api 'org.springframework.boot:spring-boot-starter'
33+
api 'org.springframework.boot:spring-boot-web-server'
3334
api "org.apache.maven:maven-resolver-provider:${mavenVersion}"
3435
api "org.apache.maven.resolver:maven-resolver-api:${mavenResolverVersion}"
3536
api "org.apache.maven.resolver:maven-resolver-spi:${mavenResolverVersion}"
@@ -42,6 +43,7 @@ dependencies {
4243
testImplementation 'org.springframework.boot:spring-boot-starter-test'
4344
testImplementation 'org.springframework.boot:spring-boot-starter-web'
4445
testImplementation 'org.springframework:spring-web'
46+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
4547
}
4648

4749
tasks.named('test') {

spring-boot-testjars/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ checkstyle {
2323
dependencies {
2424
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.40")
2525
compileOnly 'org.springframework.boot:spring-boot-loader'
26-
implementation platform('org.springframework.boot:spring-boot-dependencies:3.4.0')
26+
implementation platform('org.springframework.boot:spring-boot-dependencies:4.0.0-RC1')
2727
implementation 'org.apache.commons:commons-exec:1.3'
2828
implementation 'org.springframework:spring-test'
2929
implementation 'org.springframework.boot:spring-boot-testcontainers'
30+
implementation 'org.springframework.boot:spring-boot-web-server'
3031
testImplementation 'org.springframework.boot:spring-boot-loader'
3132
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3233
testImplementation 'org.springframework:spring-web'
34+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
3335
}
3436

3537
tasks.named('test') {

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/detector/ClassUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ final class ClassUtils {
3131
* @throws LinkageError if the class file could not be loaded
3232
* @see Class#forName(String, boolean, ClassLoader)
3333
*/
34+
@SuppressWarnings("deprecation")
3435
static Class<?> forName(String name, @Nullable ClassLoader classLoader)
3536
throws ClassNotFoundException, LinkageError {
3637

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyAutoConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@
1717
package org.springframework.experimental.boot.test.context;
1818

1919
import org.springframework.boot.autoconfigure.AutoConfiguration;
20+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2021
import org.springframework.core.Ordered;
2122
import org.springframework.core.annotation.Order;
23+
import org.springframework.test.context.DynamicPropertyRegistrar;
2224

2325
/**
2426
* Automatically imports {@code EnableDynamicProperty}.
2527
*
2628
* @author Rob Winch
29+
* @author Chris Bono
2730
*/
2831
@AutoConfiguration
2932
@Order(Ordered.HIGHEST_PRECEDENCE)
33+
@ConditionalOnClass(DynamicPropertyRegistrar.class)
3034
@EnableDynamicProperty
3135
public class DynamicPropertyAutoConfiguration {
3236

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyDefinitionRegistrar.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 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.
@@ -25,21 +25,20 @@
2525
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2626
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
2727
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
28-
import org.springframework.boot.testcontainers.properties.TestcontainersPropertySource;
2928
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
3029
import org.springframework.core.annotation.MergedAnnotation;
3130
import org.springframework.core.env.Environment;
3231
import org.springframework.core.type.AnnotationMetadata;
3332
import org.springframework.core.type.MethodMetadata;
3433
import org.springframework.test.context.DynamicPropertyRegistrar;
3534
import org.springframework.test.context.DynamicPropertyRegistry;
36-
import org.springframework.util.ClassUtils;
3735

3836
/**
3937
* Finds beans annotated with {@link DynamicProperty} and adds the properties to the
4038
* Environment.
4139
*
4240
* @author Rob Winch
41+
* @author Chris Bono
4342
*/
4443
class DynamicPropertyDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
4544

@@ -63,13 +62,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
6362
return;
6463
}
6564
if (this.beanFactory instanceof ConfigurableListableBeanFactory listableBeanFactory) {
66-
if (ClassUtils.isPresent("org.springframework.test.context.DynamicPropertyRegistrar",
67-
getClass().getClassLoader())) {
68-
registerDynamicPropertyRegistrar(listableBeanFactory, registry);
69-
}
70-
else {
71-
registerTestcontainersPropertySource(listableBeanFactory, registry);
72-
}
65+
registerDynamicPropertyRegistrar(listableBeanFactory, registry);
7366
}
7467
}
7568

@@ -93,21 +86,6 @@ private void registerDynamicPropertyRegistrar(ConfigurableListableBeanFactory be
9386
registry.registerBeanDefinition(REGISTRAR_BEAN_NAME, registrarBdb.getBeanDefinition());
9487
}
9588

96-
private void registerTestcontainersPropertySource(ConfigurableListableBeanFactory beanFactory,
97-
BeanDefinitionRegistry registry) {
98-
DynamicPropertyRegistry properties = TestcontainersPropertySource.attach(this.environment);
99-
for (String dynamicPropertyBeanName : beanFactory.getBeanNamesForAnnotation(DynamicProperty.class)) {
100-
BeanDefinition dynamicPropertyBeanDefinition = registry.getBeanDefinition(dynamicPropertyBeanName);
101-
DynamicPropertyRegistryProperty property = createRegistryProperty(dynamicPropertyBeanDefinition,
102-
dynamicPropertyBeanName);
103-
if (property == null) {
104-
throw new IllegalStateException(
105-
"Missing @DynamicProperty annotation on BeanDefinition of " + dynamicPropertyBeanName);
106-
}
107-
properties.add(property.name(), property.value());
108-
}
109-
}
110-
11189
private DynamicPropertyRegistryProperty createRegistryProperty(BeanDefinition dynamicPropertyBeanDefinition,
11290
String dynamicPropertyBeanName) {
11391
if (dynamicPropertyBeanDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition) {
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
org.springframework.context.ApplicationListener=\
2-
org.springframework.boot.web.context.WebServerPortFileWriter
2+
org.springframework.boot.web.server.context.WebServerPortFileWriter

0 commit comments

Comments
 (0)