From 0f5a0398773bea2278a4a063633e0a241a0ea8c6 Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Tue, 4 Nov 2025 12:50:39 -0600 Subject: [PATCH 1/2] 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 --- .../oauth2-login-custom-config/build.gradle | 5 ++-- .../authorizationserver/SecurityConfig.java | 19 ++++++++----- samples/oauth2-login/build.gradle | 5 ++-- spring-boot-testjars-maven/build.gradle | 4 ++- spring-boot-testjars/build.gradle | 4 ++- .../boot/server/exec/detector/ClassUtils.java | 1 + .../DynamicPropertyAutoConfiguration.java | 4 +++ .../DynamicPropertyDefinitionRegistrar.java | 28 ++----------------- .../META-INF/spring.factories | 2 +- 9 files changed, 33 insertions(+), 39 deletions(-) diff --git a/samples/oauth2-login-custom-config/build.gradle b/samples/oauth2-login-custom-config/build.gradle index 80e4a5a..c5e873b 100644 --- a/samples/oauth2-login-custom-config/build.gradle +++ b/samples/oauth2-login-custom-config/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.4.0' - id 'io.spring.dependency-management' version '1.1.2' + id 'org.springframework.boot' version '4.0.0-RC1' + id 'io.spring.dependency-management' version '1.1.7' } group = 'com.example' @@ -22,6 +22,7 @@ dependencies { testImplementation project(':spring-boot-testjars-maven') testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-oauth2-authorization-server' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { diff --git a/samples/oauth2-login-custom-config/src/test/java/testjars/authorizationserver/SecurityConfig.java b/samples/oauth2-login-custom-config/src/test/java/testjars/authorizationserver/SecurityConfig.java index 4db8ecb..8b3de64 100644 --- a/samples/oauth2-login-custom-config/src/test/java/testjars/authorizationserver/SecurityConfig.java +++ b/samples/oauth2-login-custom-config/src/test/java/testjars/authorizationserver/SecurityConfig.java @@ -28,6 +28,8 @@ import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration; +import org.springframework.security.config.annotation.web.configurers.oauth2.server.authorization.OAuth2AuthorizationServerConfigurer; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; @@ -38,8 +40,6 @@ import org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository; import org.springframework.security.oauth2.server.authorization.client.RegisteredClient; import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository; -import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration; -import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer; import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings; import org.springframework.security.oauth2.server.authorization.settings.ClientSettings; import org.springframework.security.provisioning.InMemoryUserDetailsManager; @@ -59,9 +59,14 @@ public class SecurityConfig { @Bean @Order(1) - public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) - throws Exception { - OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http); + public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) { + OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = new OAuth2AuthorizationServerConfigurer(); + http + .securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) + .with(authorizationServerConfigurer, Customizer.withDefaults()) + .authorizeHttpRequests((authorize) -> + authorize.anyRequest().authenticated() + ); http.getConfigurer(OAuth2AuthorizationServerConfigurer.class) .oidc(Customizer.withDefaults()); // Enable OpenID Connect 1.0 http @@ -82,8 +87,7 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h @Bean @Order(2) - public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) - throws Exception { + public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) { http .authorizeHttpRequests((authorize) -> authorize .anyRequest().authenticated() @@ -96,6 +100,7 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) return http.build(); } + @SuppressWarnings("deprecation") @Bean public UserDetailsService userDetailsService() { UserDetails userDetails = User.withDefaultPasswordEncoder() diff --git a/samples/oauth2-login/build.gradle b/samples/oauth2-login/build.gradle index f66751b..fdd0d2b 100644 --- a/samples/oauth2-login/build.gradle +++ b/samples/oauth2-login/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.4.0' - id 'io.spring.dependency-management' version '1.1.2' + id 'org.springframework.boot' version '4.0.0-RC1' + id 'io.spring.dependency-management' version '1.1.7' } group = 'com.example' @@ -21,6 +21,7 @@ dependencies { testImplementation project(':spring-boot-testjars') testImplementation project(':spring-boot-testjars-maven') testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { diff --git a/spring-boot-testjars-maven/build.gradle b/spring-boot-testjars-maven/build.gradle index 51fe0f6..922efc3 100644 --- a/spring-boot-testjars-maven/build.gradle +++ b/spring-boot-testjars-maven/build.gradle @@ -28,8 +28,9 @@ checkstyle { dependencies { checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.40") api project(':spring-boot-testjars') - api platform('org.springframework.boot:spring-boot-dependencies:3.4.0') + api platform('org.springframework.boot:spring-boot-dependencies:4.0.0-RC1') api 'org.springframework.boot:spring-boot-starter' + api 'org.springframework.boot:spring-boot-web-server' api "org.apache.maven:maven-resolver-provider:${mavenVersion}" api "org.apache.maven.resolver:maven-resolver-api:${mavenResolverVersion}" api "org.apache.maven.resolver:maven-resolver-spi:${mavenResolverVersion}" @@ -42,6 +43,7 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework:spring-web' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { diff --git a/spring-boot-testjars/build.gradle b/spring-boot-testjars/build.gradle index 11e781b..a07970d 100644 --- a/spring-boot-testjars/build.gradle +++ b/spring-boot-testjars/build.gradle @@ -23,13 +23,15 @@ checkstyle { dependencies { checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.40") compileOnly 'org.springframework.boot:spring-boot-loader' - implementation platform('org.springframework.boot:spring-boot-dependencies:3.4.0') + implementation platform('org.springframework.boot:spring-boot-dependencies:4.0.0-RC1') implementation 'org.apache.commons:commons-exec:1.3' implementation 'org.springframework:spring-test' implementation 'org.springframework.boot:spring-boot-testcontainers' + implementation 'org.springframework.boot:spring-boot-web-server' testImplementation 'org.springframework.boot:spring-boot-loader' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework:spring-web' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { diff --git a/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/detector/ClassUtils.java b/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/detector/ClassUtils.java index 28acb2e..0bed100 100644 --- a/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/detector/ClassUtils.java +++ b/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/detector/ClassUtils.java @@ -31,6 +31,7 @@ final class ClassUtils { * @throws LinkageError if the class file could not be loaded * @see Class#forName(String, boolean, ClassLoader) */ + @SuppressWarnings("deprecation") static Class forName(String name, @Nullable ClassLoader classLoader) throws ClassNotFoundException, LinkageError { diff --git a/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyAutoConfiguration.java b/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyAutoConfiguration.java index 11f7489..6cee12c 100644 --- a/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyAutoConfiguration.java +++ b/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyAutoConfiguration.java @@ -17,16 +17,20 @@ package org.springframework.experimental.boot.test.context; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; +import org.springframework.test.context.DynamicPropertyRegistrar; /** * Automatically imports {@code EnableDynamicProperty}. * * @author Rob Winch + * @author Chris Bono */ @AutoConfiguration @Order(Ordered.HIGHEST_PRECEDENCE) +@ConditionalOnClass(DynamicPropertyRegistrar.class) @EnableDynamicProperty public class DynamicPropertyAutoConfiguration { diff --git a/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyDefinitionRegistrar.java b/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyDefinitionRegistrar.java index 0bc58cc..597dcae 100644 --- a/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyDefinitionRegistrar.java +++ b/spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyDefinitionRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 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. @@ -25,7 +25,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.boot.testcontainers.properties.TestcontainersPropertySource; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.env.Environment; @@ -33,13 +32,13 @@ import org.springframework.core.type.MethodMetadata; import org.springframework.test.context.DynamicPropertyRegistrar; import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.util.ClassUtils; /** * Finds beans annotated with {@link DynamicProperty} and adds the properties to the * Environment. * * @author Rob Winch + * @author Chris Bono */ class DynamicPropertyDefinitionRegistrar implements ImportBeanDefinitionRegistrar { @@ -63,13 +62,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B return; } if (this.beanFactory instanceof ConfigurableListableBeanFactory listableBeanFactory) { - if (ClassUtils.isPresent("org.springframework.test.context.DynamicPropertyRegistrar", - getClass().getClassLoader())) { - registerDynamicPropertyRegistrar(listableBeanFactory, registry); - } - else { - registerTestcontainersPropertySource(listableBeanFactory, registry); - } + registerDynamicPropertyRegistrar(listableBeanFactory, registry); } } @@ -93,21 +86,6 @@ private void registerDynamicPropertyRegistrar(ConfigurableListableBeanFactory be registry.registerBeanDefinition(REGISTRAR_BEAN_NAME, registrarBdb.getBeanDefinition()); } - private void registerTestcontainersPropertySource(ConfigurableListableBeanFactory beanFactory, - BeanDefinitionRegistry registry) { - DynamicPropertyRegistry properties = TestcontainersPropertySource.attach(this.environment); - for (String dynamicPropertyBeanName : beanFactory.getBeanNamesForAnnotation(DynamicProperty.class)) { - BeanDefinition dynamicPropertyBeanDefinition = registry.getBeanDefinition(dynamicPropertyBeanName); - DynamicPropertyRegistryProperty property = createRegistryProperty(dynamicPropertyBeanDefinition, - dynamicPropertyBeanName); - if (property == null) { - throw new IllegalStateException( - "Missing @DynamicProperty annotation on BeanDefinition of " + dynamicPropertyBeanName); - } - properties.add(property.name(), property.value()); - } - } - private DynamicPropertyRegistryProperty createRegistryProperty(BeanDefinition dynamicPropertyBeanDefinition, String dynamicPropertyBeanName) { if (dynamicPropertyBeanDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition) { diff --git a/spring-boot-testjars/src/main/resources/org/springframework/experimental/boot/testjars/classpath-entries/META-INF/spring.factories b/spring-boot-testjars/src/main/resources/org/springframework/experimental/boot/testjars/classpath-entries/META-INF/spring.factories index ee29da2..dfa99eb 100644 --- a/spring-boot-testjars/src/main/resources/org/springframework/experimental/boot/testjars/classpath-entries/META-INF/spring.factories +++ b/spring-boot-testjars/src/main/resources/org/springframework/experimental/boot/testjars/classpath-entries/META-INF/spring.factories @@ -1,2 +1,2 @@ org.springframework.context.ApplicationListener=\ -org.springframework.boot.web.context.WebServerPortFileWriter \ No newline at end of file +org.springframework.boot.web.server.context.WebServerPortFileWriter From a0456e0913acaca04d6015699f2e4dc7a26990b6 Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Tue, 4 Nov 2025 18:00:46 -0600 Subject: [PATCH 2/2] Update version Signed-off-by: Chris Bono --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 037b317..1704855 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.0.7-SNAPSHOT +version=0.1.0-SNAPSHOT