Skip to content

dsyer/spring-boot-initializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This application is a proof of concept for how to support functional bean registration in Spring Boot. See spring-projects/spring-boot#8115 for background.

The approach here is to provide a modified version of Spring Boot's (internal) BeanDefinitionLoader. Example app:

@SpringBootApplication
public class InitializerApplication
		implements ApplicationContextInitializer<GenericApplicationContext> {

	public static void main(String[] args) {
		SpringApplication.run(InitializerApplication.class, args);
	}

	@Override
	public void initialize(GenericApplicationContext context) {
		context.registerBean(RouterFunction.class, this::userEndpoints);
	}

	private RouterFunction<?> userEndpoints() {
		return route(GET("/"), request -> ok().body(Mono.just("Hello"), String.class));
	}

}

This works as a main application class and in integration tests because the same BeanDefinitionLoader is used.

There is also a custom AutoConfigurationImportSelectorAutoConfigurationImportSelector which looks at autoconfig classes to see if they are ApplicationContextInitializer. If so the initializer is applied to the current context and the autoimport is cancelled.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages