piątek, 19 sierpnia 2016

Ratpack And Spring Getting Started

git

Maven dependendencies

        
            io.ratpack
            ratpack-core
            1.3.3
        

Spring initialization

@Configuration
@Profile(WEB_CONSOLE)
public class WebConsoleConfiguration {

    @Bean
    public ServerConfigBuilder webServerConfig() {
        ServerConfigBuilder embedded = ServerConfig.embedded();
        embedded.sysProps();
        return embedded;
    }

    @Bean
    public RatpackServer webServer(ServerConfigBuilder config) throws Exception {
        RatpackServer server = RatpackServer.of(b -> b
                .serverConfig(config)
                .registryOf(r -> r.add(String.class, "world"))
                .handlers(chain -> chain
                        .get("hello", ctx -> {
                            ctx.render(ctx.get(String.class) + " !");
                        })
                        .get("metrics", ctx -> {
                            ctx.render("Ooo..");
                        })
                )
        );
        server.start();
        return server;
    }

}

Brak komentarzy:

Prześlij komentarz