public abstract class Spring extends Object
import org.springframework.boot.SpringApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import ratpack.test.embed.EmbeddedApp; import static ratpack.spring.Spring.spring; public class Example { public static void main(String[] args) { EmbeddedApp.fromChain(chain -> chain .register(spring(ExampleSpringBootApp.class)) .handler(context -> { String helloBean = context.get(String.class); context.render(helloBean); }) ).test(httpClient -> { assert httpClient.getText().equals("hello"); }); } @Configuration public static class ExampleSpringBootApp { @Bean String hello() { return "hello"; } public static void main(String... args) { SpringApplication.run(ExampleSpringBootApp.class, args); } } }
Constructor and Description |
---|
Spring() |
Modifier and Type | Method and Description |
---|---|
static Registry |
spring(Class<?> clazz,
String... args)
Creates a registry backed by the given Spring Boot application class.
|
static Registry |
spring(ListableBeanFactory beanFactory)
Creates a registry backed by the given bean factory.
|
static Registry |
spring(SpringApplicationBuilder builder,
String... args)
Creates a registry backed by the given Spring Boot application builder.
|
public static Registry spring(ListableBeanFactory beanFactory)
Note: Spring ListableBeanFactory API doesn't current support looking up beans with parameterized types.
The adapted Registry
instance doesn't support this because of this limitation.
There is a feature request to add the generics functionality to the Spring ListableBeanFactory API.
beanFactory
- the bean factory to back the registrypublic static Registry spring(Class<?> clazz, String... args)
clazz
- a Spring Boot application classargs
- any arguments to pass to the applicationspring(org.springframework.beans.factory.ListableBeanFactory)
public static Registry spring(SpringApplicationBuilder builder, String... args)
builder
- a Spring Boot application builderargs
- any arguments to pass to the applicationspring(org.springframework.beans.factory.ListableBeanFactory)