Skip to content

Introduce RuntimeHintsRegistrar #28160

Closed
Closed
@sdeleuze

Description

@sdeleuze

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.

Metadata

Metadata

Assignees

Labels

theme: aotAn issue related to Ahead-of-time processingtype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions