diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java index 67e69ed07f..ee5e43c05c 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java @@ -22,11 +22,12 @@ import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeHint.Builder; import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.annotation.ReflectiveRuntimeHintsRegistrar; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** * {@link RuntimeHintsRegistrar} implementation that makes sure {@link SchedulerFactoryBean} - * reflection entries are registered. + * reflection hints are registered. * * @author Sebastien Deleuze * @author Stephane Nicoll @@ -40,7 +41,7 @@ class SchedulerFactoryBeanRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { if (!ClassUtils.isPresent(SCHEDULER_FACTORY_CLASS_NAME, classLoader)) { return; } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionForBinding.java b/spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionForBinding.java index d8e8be8ada..6062af631e 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionForBinding.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionForBinding.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -63,7 +63,7 @@ import org.springframework.core.annotation.AliasFor; * @see org.springframework.aot.hint.BindingReflectionHintsRegistrar * @see Reflective @Reflective */ -@Target({ ElementType.TYPE, ElementType.METHOD }) +@Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented @Reflective(RegisterReflectionForBindingProcessor.class) @@ -77,8 +77,7 @@ public @interface RegisterReflectionForBinding { /** * Classes for which reflection hints should be registered. - *

At least one class must be specified either via {@link #value} or - * {@code #classes}. + *

At least one class must be specified either via {@link #value} or {@code classes}. * @see #value() */ @AliasFor("value") diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java index 9d8318e438..8081223c52 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -47,9 +47,11 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + ClassLoader classLoaderToUse = (classLoader != null ? classLoader : + SpringFactoriesLoaderRuntimeHints.class.getClassLoader()); for (String resourceLocation : RESOURCE_LOCATIONS) { - registerHints(hints, classLoader, resourceLocation); + registerHints(hints, classLoaderToUse, resourceLocation); } } @@ -63,6 +65,7 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar { private void registerHints(RuntimeHints hints, ClassLoader classLoader, String factoryClassName, List implementationClassNames) { + Class factoryClass = resolveClassName(classLoader, factoryClassName); if (factoryClass == null) { if (logger.isTraceEnabled()) { @@ -100,6 +103,7 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar { } } + private static class ExtendedSpringFactoriesLoader extends SpringFactoriesLoader { ExtendedSpringFactoriesLoader(@Nullable ClassLoader classLoader, Map> factories) { @@ -109,7 +113,6 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar { static Map> accessLoadFactoriesResource(ClassLoader classLoader, String resourceLocation) { return SpringFactoriesLoader.loadFactoriesResource(classLoader, resourceLocation); } - } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java index f39c3cc0e2..9f44861ed8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -21,11 +21,12 @@ import java.util.Collections; import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.lang.Nullable; /** - * {@link RuntimeHintsRegistrar} implementation that registers reflection hints for - * {@code EmbeddedDataSourceProxy#shutdown} in order to allow it to be used as a bean - * destroy method. + * {@link RuntimeHintsRegistrar} implementation that registers reflection hints + * for {@code EmbeddedDataSourceProxy#shutdown} in order to allow it to be used + * as a bean destroy method. * * @author Sebastien Deleuze * @since 6.0 @@ -33,7 +34,7 @@ import org.springframework.aot.hint.RuntimeHintsRegistrar; class EmbeddedDatabaseFactoryRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { hints.reflection().registerTypeIfPresent(classLoader, "org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory$EmbeddedDataSourceProxy", builder -> builder diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java index eb6e204028..72891dffdc 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -22,6 +22,7 @@ import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -41,8 +42,9 @@ class EntityManagerRuntimeHints implements RuntimeHintsRegistrar { private static final String NATIVE_QUERY_IMPL_CLASS_NAME = "org.hibernate.query.sql.internal.NativeQueryImpl"; + @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { if (ClassUtils.isPresent(HIBERNATE_SESSION_FACTORY_CLASS_NAME, classLoader)) { hints.proxies().registerJdkProxy(TypeReference.of(HIBERNATE_SESSION_FACTORY_CLASS_NAME), TypeReference.of(EntityManagerFactoryInfo.class)); @@ -70,4 +72,5 @@ class EntityManagerRuntimeHints implements RuntimeHintsRegistrar { catch (ClassNotFoundException ignored) { } } + } diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java index f5cdc81adf..6b2ce490f6 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -21,11 +21,12 @@ import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeHint; import org.springframework.aot.hint.TypeReference; +import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionDefinition; /** - * {@link RuntimeHintsRegistrar} implementation that registers runtime hints for - * transaction management. + * {@link RuntimeHintsRegistrar} implementation that registers runtime hints + * for transaction management. * * @author Sebastien Deleuze * @since 6.0 @@ -34,9 +35,9 @@ import org.springframework.transaction.TransactionDefinition; class TransactionRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - hints.reflection().registerTypes(TypeReference.listOf( - Isolation.class, Propagation.class, TransactionDefinition.class), + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + hints.reflection().registerTypes( + TypeReference.listOf(Isolation.class, Propagation.class, TransactionDefinition.class), TypeHint.builtWith(MemberCategory.DECLARED_FIELDS)); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java b/spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java index b6619f1f20..f7f07a9a7f 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -22,9 +22,10 @@ import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeHint.Builder; +import org.springframework.lang.Nullable; /** - * {@link RuntimeHintsRegistrar} implementation that registers reflection entries + * {@link RuntimeHintsRegistrar} implementation that registers reflection hints * for {@link Jackson2ObjectMapperBuilder} well-known modules. * * @author Sebastien Deleuze @@ -38,7 +39,7 @@ class JacksonModulesRuntimeHints implements RuntimeHintsRegistrar { .withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { hints.reflection() .registerTypeIfPresent(classLoader, "com.fasterxml.jackson.datatype.jdk8.Jdk8Module", asJacksonModule) diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java b/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java index 3f569c44d3..d04fda433f 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -20,10 +20,11 @@ import org.springframework.aot.hint.BindingReflectionHintsRegistrar; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.http.ProblemDetail; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** - * {@link RuntimeHintsRegistrar} implementation that registers binding reflection entries + * {@link RuntimeHintsRegistrar} implementation that registers binding reflection hints * for {@link ProblemDetail} serialization support with Jackson. * * @author Brian Clozel @@ -33,7 +34,7 @@ import org.springframework.util.ClassUtils; class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar(); bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetail.class); if (ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader)) { diff --git a/spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java b/spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java index 06976e58cd..dfff61eea9 100644 --- a/spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java +++ b/spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -19,10 +19,11 @@ package org.springframework.web.util; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.core.io.ClassPathResource; +import org.springframework.lang.Nullable; /** - * {@link RuntimeHintsRegistrar} implementation that registers resource - * hints for web util resources. + * {@link RuntimeHintsRegistrar} implementation that registers resource hints + * for resources in the {@code web.util} package. * * @author Sebastien Deleuze * @since 6.0 @@ -30,7 +31,7 @@ import org.springframework.core.io.ClassPathResource; class WebUtilRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { hints.resources().registerResource( new ClassPathResource("HtmlCharacterEntityReferences.properties", getClass())); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java index f10e55ce5e..d931aa3ea2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -19,10 +19,11 @@ package org.springframework.web.reactive.socket.server.support; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.lang.Nullable; /** - * {@link RuntimeHintsRegistrar} implementation that registers reflection hints related to - * {@link HandshakeWebSocketService}. + * {@link RuntimeHintsRegistrar} implementation that registers reflection hints + * related to {@link HandshakeWebSocketService}. * * @author Sebastien Deleuze * @since 6.0 @@ -30,8 +31,9 @@ import org.springframework.aot.hint.RuntimeHintsRegistrar; class HandshakeWebSocketServiceRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { hints.reflection().registerType(HandshakeWebSocketService.initUpgradeStrategy().getClass(), MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); } + } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeHandlerRuntimeHints.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeHandlerRuntimeHints.java index fb00ca8f83..0e8fbe82e2 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeHandlerRuntimeHints.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeHandlerRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -21,10 +21,11 @@ import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; +import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** - * {@link RuntimeHintsRegistrar} implementation that registers reflection entries + * {@link RuntimeHintsRegistrar} implementation that registers reflection hints * for {@link AbstractHandshakeHandler}. * * @author Sebastien Deleuze @@ -60,8 +61,9 @@ class HandshakeHandlerRuntimeHints implements RuntimeHintsRegistrar { "com.ibm.websphere.wsoc.WsWsocServerContainer", classLoader); } + @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { ReflectionHints reflectionHints = hints.reflection(); if (tomcatWsPresent) { registerType(reflectionHints, "org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy"); @@ -87,4 +89,5 @@ class HandshakeHandlerRuntimeHints implements RuntimeHintsRegistrar { reflectionHints.registerType(TypeReference.of(className), builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); } + }