Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce RuntimeHintsRegistrar #28160

Closed
sdeleuze opened this issue Mar 11, 2022 · 1 comment
Closed

Introduce RuntimeHintsRegistrar #28160

sdeleuze opened this issue Mar 11, 2022 · 1 comment
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@sdeleuze
Copy link
Contributor

In order to provide the possibility for registering RuntimeHints, the proposal is to introduce a RuntimeHintsRegistrar abstraction designed to address the same needs than BeanFactoryNativeConfigurationProcessor and BeanNativeConfigurationProcessor in Spring Native. It could even be used initially to register static hints as done with @NativeHint annotations.

package org.springframework.beans.factory.hint;

public interface RuntimeHintsRegistrar {

	void registerHints(RuntimeHints hints, ListableBeanFactory beanFactory);

	default void ifPresent(String className, Runnable runnable) {
		if (ClassUtils.isPresent(className, null)) {
			runnable.run();
		}
	}
}

The registerIfPresent method is designed to provide a more discoverable mechanism to prevent ClassNotFoundException errors than inner classes.

Since they are designed to be used only AOT, spring.factories is not a good fit here, so implementations could be registered via a META-INF/spring/org.springframework.beans.factory.hint.RuntimeHintsRegistrar.imports file with the same format than org.springframework.boot.autoconfigure.AutoConfiguration.imports.

@sdeleuze sdeleuze added type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels Mar 11, 2022
@sdeleuze sdeleuze added this to the 6.0.0-M4 milestone Mar 11, 2022
@snicoll
Copy link
Member

snicoll commented Mar 11, 2022

Since they are designed to be used only AOT, spring.factories is not a good fit here

I don't necessarily disagree but it is disruptive to introduce another mechanism for that reason alone. There are many other concepts in the core container that behave differently when AOT is involved. For instance, we could imagine a class-level annotation on the type that provides some opt-in metadata that the transformer can use to ignore those entries.

I am not huge fan of the factory.hint package. Perhaps it is a smell that something named RuntimeHintsRegistrar is taking the bean factory as an argument?

cc @philwebb as I know he's been brainstorming on this topic as well.

@philwebb philwebb self-assigned this Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants