or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

aop.mdconfiguration.mddependency-injection.mdfunctions.mdhttp-client.mdhttp-server.mdindex.mdmanagement.mdmessaging.mdreactive.mdretry.mdscheduling.mdwebsocket.md
tile.json

tessl/maven-micronaut

Modern, JVM-based framework for building modular, easily testable microservice and serverless applications with compile-time DI and fast startup.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.micronaut/micronaut-core@4.9.x

To install, run

npx @tessl/cli install tessl/maven-micronaut@4.9.0

index.mddocs/

Micronaut Framework

Micronaut is a modern, JVM-based framework designed for building modular, easily testable microservice and serverless applications. It provides dependency injection, AOP, auto-configuration, distributed configuration, service discovery, HTTP routing, and client-side load balancing while achieving fast startup time, reduced memory footprint, minimal reflection usage, and no runtime bytecode generation through compile-time framework infrastructure computation.

Package Information

  • Package Name: micronaut-core
  • Package Type: maven
  • Language: Java (with Kotlin and Groovy support)
  • Installation: See Installation Guide

Core Imports

import io.micronaut.context.ApplicationContext;
import io.micronaut.runtime.Micronaut;
import io.micronaut.http.annotation.*;
import io.micronaut.context.annotation.*;
import jakarta.inject.*;

Gradle dependencies:

implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-http-server-netty")
implementation("io.micronaut:micronaut-inject")
implementation("io.micronaut:micronaut-context")

Basic Usage

import io.micronaut.runtime.Micronaut;
import io.micronaut.http.annotation.*;
import jakarta.inject.Singleton;

@Controller("/hello")
public class HelloController {
    
    @Get("/{name}")
    public String hello(String name) {
        return "Hello " + name;
    }
}

@Singleton
public class GreetingService {
    public String createGreeting(String name) {
        return "Hello " + name + "!";
    }
}

// Application main class
public class Application {
    public static void main(String[] args) {
        Micronaut.run(Application.class, args);
    }
}

Architecture

Micronaut is built around several key architectural principles:

  • Compile-time DI: Dependency injection resolution occurs at compile time, eliminating reflection overhead
  • Bean Introspection: Compile-time generation of bean metadata for fast startup
  • Reactive Programming: Built-in support for reactive streams and non-blocking I/O
  • Annotation Processing: Extensive use of annotation processors for framework infrastructure
  • Modular Design: Highly modular architecture allowing selective feature inclusion
  • Cloud Native: Designed for cloud deployment with support for service discovery, distributed configuration, and monitoring

Capabilities

Dependency Injection

Compile-time dependency injection container with no reflection, providing fast application startup and minimal memory footprint.

@Singleton
public class ServiceExample {
    private final Repository repository;
    
    public ServiceExample(Repository repository) {
        this.repository = repository;
    }
}

@Bean
public Repository createRepository() {
    return new DatabaseRepository();
}

Dependency Injection

HTTP Server

High-performance HTTP server with both blocking and non-blocking APIs, supporting reactive programming patterns.

@Controller("/api")
public class ApiController {
    
    @Get("/users/{id}")
    Single<User> getUser(Long id) {
        return userService.findById(id);
    }
    
    @Post("/users")
    Single<HttpResponse<User>> createUser(@Body User user) {
        return userService.save(user)
            .map(HttpResponse::created);
    }
}

HTTP Server

HTTP Client

Declarative HTTP client with reactive support, service discovery integration, and comprehensive error handling.

@Client("/api")
public interface UserClient {
    
    @Get("/users/{id}")
    Single<User> getUser(Long id);
    
    @Post("/users")
    Single<User> createUser(@Body User user);
}

HTTP Client

Configuration

Type-safe configuration binding with environment-specific property loading and hot-reload support for development.

@ConfigurationProperties("app.database")
public class DatabaseConfiguration {
    private String host;
    private int port;
    private String username;
    
    // getters and setters
}

Configuration

Aspect-Oriented Programming

Compile-time AOP with method and constructor interception, providing around advice and introduction support without runtime proxy generation.

@Around
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface Timed {
}

@Singleton
public class TimedInterceptor implements MethodInterceptor<Object, Object> {
    @Override
    public Object intercept(InvocationContext<Object, Object> context) {
        // timing logic
        return context.proceed();
    }
}

Aspect-Oriented Programming

Reactive Programming

Full reactive streams support with backpressure handling, enabling non-blocking I/O operations throughout the framework.

@Controller("/stream")
public class StreamController {
    
    @Get(value = "/events", produces = MediaType.TEXT_EVENT_STREAM)
    Publisher<String> events() {
        return Flowable.interval(1, TimeUnit.SECONDS)
            .map(i -> "Event " + i);
    }
}

Reactive Programming

Scheduling and Async

Task scheduling and asynchronous execution with configurable thread pools and execution contexts.

@Singleton
public class ScheduledService {
    
    @Scheduled(fixedDelay = "5s")
    void periodicTask() {
        // scheduled task logic
    }
    
    @Async
    CompletableFuture<String> asyncOperation() {
        return CompletableFuture.completedFuture("result");
    }
}

Scheduling and Async

WebSocket Support

Full-duplex WebSocket communication with both client and server implementations.

@ServerWebSocket("/ws")
public class ChatWebSocket {
    
    @OnOpen
    public void onOpen(WebSocketSession session) {
        // connection opened
    }
    
    @OnMessage
    public void onMessage(String message, WebSocketSession session) {
        session.sendSync(message, MediaType.TEXT_PLAIN_TYPE);
    }
}

WebSocket Support

Message-Driven Applications

Support for building message-driven applications with various messaging systems.

@MessageListener
public class MessageHandler {
    
    @MessageMapping("user.created")
    void handleUserCreated(@MessageBody User user) {
        // handle user creation event
    }
}

Messaging

Application Management

Built-in management endpoints for health checks, metrics, and application information.

@Endpoint(id = "custom", defaultEnabled = true)
public class CustomEndpoint {
    
    @Read
    public Map<String, Object> status() {
        return Map.of("status", "healthy");
    }
}

Management

Retry and Circuit Breaker

Resilience patterns with configurable retry logic and circuit breaker implementation.

@Singleton
public class ExternalService {
    
    @Retryable(attempts = "3", delay = "1s")
    public String callExternal() {
        // external service call
    }
    
    @CircuitBreaker
    public String reliableCall() {
        // call with circuit breaker protection
    }
}

Retry and Circuit Breaker

Function as a Service

Support for serverless functions with integration for AWS Lambda, Google Cloud Functions, and Azure Functions.

@FunctionBean("hello")
public class HelloFunction implements Function<String, String> {
    
    @Override
    public String apply(String input) {
        return "Hello " + input;
    }
}

Function as a Service

Types

// Core application context
public interface ApplicationContext extends BeanContext, LifeCycle<ApplicationContext> {
    static ApplicationContext build();
    static ApplicationContext run();
    static ApplicationContext run(String... args);
}

// Main application runner
public final class Micronaut {
    public static ApplicationContext run();
    public static ApplicationContext run(String... args);
    public static ApplicationContext run(Class<?> cls, String... args);
}

// HTTP request/response types
public interface HttpRequest<B> extends HttpMessage<B> {
    HttpMethod getMethod();
    URI getUri();
    String getPath();
    Map<String, Object> getAttributes();
}

public interface HttpResponse<B> extends HttpMessage<B> {
    HttpStatus getStatus();
    int code();
    String reason();
}

// Bean definition and context
public interface BeanDefinition<T> extends BeanType<T> {
    Class<T> getBeanType();
    Optional<Class<?>> getDeclaringType();
    boolean isEnabled(BeanContext context);
}

public interface BeanContext extends BeanLocator, LifeCycle<BeanContext> {
    <T> T getBean(Class<T> beanType);
    <T> Optional<T> findBean(Class<T> beanType);
    <T> Collection<T> getBeansOfType(Class<T> beanType);
}