BAEL-1026 (#2322)
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
0a631ac326
commit
9e193396ef
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public interface ArticleList {
|
||||
|
||||
List<String> articles();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@Configuration
|
||||
public class Config {
|
||||
|
||||
@Bean
|
||||
public Content content() {
|
||||
return () -> "hello baeldung!";
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ArticleList articles() {
|
||||
return () -> Arrays.asList("Introduction to Ratpack", "Ratpack Google Guice Integration", "Ratpack Spring Boot Integration");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public interface Content {
|
||||
|
||||
String body();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import ratpack.func.Action;
|
||||
import ratpack.handling.Chain;
|
||||
import ratpack.server.ServerConfig;
|
||||
import ratpack.spring.config.EnableRatpack;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableRatpack
|
||||
public class EmbedRatpackApp {
|
||||
|
||||
@Autowired private Content content;
|
||||
@Autowired private ArticleList list;
|
||||
|
||||
@Bean
|
||||
public Action<Chain> hello() {
|
||||
return chain -> chain.get("hello", ctx -> ctx.render(content.body()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Action<Chain> list() {
|
||||
return chain -> chain.get("list", ctx -> ctx.render(list
|
||||
.articles()
|
||||
.toString()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServerConfig ratpackServerConfig() {
|
||||
return ServerConfig
|
||||
.builder()
|
||||
.findBaseDir("public")
|
||||
.build();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EmbedRatpackApp.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import ratpack.server.RatpackServer;
|
||||
|
||||
import static ratpack.spring.Spring.spring;
|
||||
|
||||
public class EmbedSpringBootApp {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
RatpackServer.start(server -> server
|
||||
.registry(spring(Config.class))
|
||||
.handlers(chain -> chain.get(ctx -> ctx.render(ctx
|
||||
.get(Content.class)
|
||||
.body()))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user