public abstract class Spring
extends java.lang.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;
import static org.junit.Assert.assertEquals;
public class Example {
public static void main(String[] args) throws Exception {
EmbeddedApp.fromHandlers(chain -> chain
.register(spring(ExampleSpringBootApp.class))
.all(context -> {
String helloBean = context.get(String.class);
context.render(helloBean);
})
).test(httpClient -> {
assertEquals("hello", httpClient.getText());
});
}
@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(java.lang.Class<?> clazz,
java.lang.String... args)
Creates a registry backed by the given Spring Boot application class.
|
static Registry |
spring(org.springframework.beans.factory.ListableBeanFactory beanFactory)
Creates a registry backed by the given bean factory.
|
static Registry |
spring(org.springframework.boot.builder.SpringApplicationBuilder builder,
java.lang.String... args)
Creates a registry backed by the given Spring Boot application builder.
|
public static Registry spring(org.springframework.beans.factory.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(java.lang.Class<?> clazz, java.lang.String... args)
clazz
- a Spring Boot application classargs
- any arguments to pass to the applicationspring(org.springframework.beans.factory.ListableBeanFactory)
public static Registry spring(org.springframework.boot.builder.SpringApplicationBuilder builder, java.lang.String... args)
builder
- a Spring Boot application builderargs
- any arguments to pass to the applicationspring(org.springframework.beans.factory.ListableBeanFactory)