Package ratpack.spring
Class Spring
- java.lang.Object
-
- ratpack.spring.Spring
-
public abstract class Spring extends Object
Methods to facilitate integrating Spring Boot with Ratpack.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.jupiter.api.Assertions.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 Summary
Constructors Constructor Description Spring()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Registry
spring(Class<?> clazz, 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, String... args)
Creates a registry backed by the given Spring Boot application builder.
-
-
-
Method Detail
-
spring
public static Registry spring(org.springframework.beans.factory.ListableBeanFactory beanFactory)
Creates a registry backed by the given bean factory.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.- Parameters:
beanFactory
- the bean factory to back the registry- Returns:
- a registry that retrieves objects from the given bean factory
-
spring
public static Registry spring(Class<?> clazz, String... args)
Creates a registry backed by the given Spring Boot application class.- Parameters:
clazz
- a Spring Boot application classargs
- any arguments to pass to the application- Returns:
- a registry that retrieves objects from the given application's bean factory
- See Also:
spring(org.springframework.beans.factory.ListableBeanFactory)
-
spring
public static Registry spring(org.springframework.boot.builder.SpringApplicationBuilder builder, String... args)
Creates a registry backed by the given Spring Boot application builder.- Parameters:
builder
- a Spring Boot application builderargs
- any arguments to pass to the application- Returns:
- a registry that retrieves objects from the given application's bean factory
- See Also:
spring(org.springframework.beans.factory.ListableBeanFactory)
-
-