Search in sources :

Example 1 with NettyEmbeddedServer

use of io.micronaut.http.server.netty.NettyEmbeddedServer in project micronaut-core by micronaut-projects.

the class SecondaryNettyServer method nettyEmbeddedServer.

@Named(SERVER_ID)
@Context
// <2>
@Bean(preDestroy = "close")
@Requires(beans = Environment.class)
NettyEmbeddedServer nettyEmbeddedServer(NettyEmbeddedServerFactory serverFactory) {
    // <3>
    // configure server programmatically
    final NettyHttpServerConfiguration configuration = // <4>
    new NettyHttpServerConfiguration();
    // <5>
    final ServerSslConfiguration sslConfiguration = new ServerSslConfiguration();
    sslConfiguration.setBuildSelfSigned(true);
    sslConfiguration.setEnabled(true);
    // random port
    sslConfiguration.setPort(-1);
    // <6>
    final NettyEmbeddedServer embeddedServer = serverFactory.build(configuration, sslConfiguration);
    // <7>
    embeddedServer.start();
    // <8>
    return embeddedServer;
}
Also used : NettyHttpServerConfiguration(io.micronaut.http.server.netty.configuration.NettyHttpServerConfiguration) ServerSslConfiguration(io.micronaut.http.ssl.ServerSslConfiguration) NettyEmbeddedServer(io.micronaut.http.server.netty.NettyEmbeddedServer) Context(io.micronaut.context.annotation.Context) Named(jakarta.inject.Named) Requires(io.micronaut.context.annotation.Requires) Bean(io.micronaut.context.annotation.Bean)

Aggregations

Bean (io.micronaut.context.annotation.Bean)1 Context (io.micronaut.context.annotation.Context)1 Requires (io.micronaut.context.annotation.Requires)1 NettyEmbeddedServer (io.micronaut.http.server.netty.NettyEmbeddedServer)1 NettyHttpServerConfiguration (io.micronaut.http.server.netty.configuration.NettyHttpServerConfiguration)1 ServerSslConfiguration (io.micronaut.http.ssl.ServerSslConfiguration)1 Named (jakarta.inject.Named)1