Convert Figma logo to code with AI

micronaut-projects logomicronaut-core

Micronaut Application Framework

6,034
1,055
6,034
751

Top Related Projects

Spring Boot

13,537

Quarkus: Supersonic Subatomic Java.

14,240

Vert.x is a tool-kit for building reactive applications on the JVM

7,485

A simple and modern Java and Kotlin web framework

3,481

Java libraries for writing microservices

A damn simple library for building production-ready RESTful web services.

Quick Overview

Micronaut is a modern, JVM-based, full-stack framework for building modular, easily testable microservice and serverless applications. It provides a compile-time dependency injection and aspect-oriented programming runtime, along with support for cloud-native features and reactive programming.

Pros

  • Fast startup time and low memory footprint due to compile-time dependency injection
  • Built-in support for cloud-native features like service discovery, distributed tracing, and configuration
  • Excellent support for reactive programming and non-blocking I/O
  • Comprehensive testing support with built-in mocking and easy-to-use test utilities

Cons

  • Steeper learning curve compared to some other Java frameworks, especially for developers new to reactive programming
  • Smaller community and ecosystem compared to more established frameworks like Spring
  • Limited documentation and resources for advanced use cases
  • Some features may require additional dependencies, increasing project complexity

Code Examples

  1. Creating a simple HTTP server:
import io.micronaut.runtime.Micronaut;
import io.micronaut.http.annotation.*;

@Controller("/hello")
public class HelloController {

    @Get("/{name}")
    public String hello(String name) {
        return "Hello, " + name + "!";
    }

    public static void main(String[] args) {
        Micronaut.run(HelloController.class, args);
    }
}
  1. Dependency injection example:
import jakarta.inject.Singleton;
import io.micronaut.context.annotation.Requires;

@Singleton
@Requires(property = "feature.enabled", value = "true")
public class FeatureService {
    public String doSomething() {
        return "Feature is enabled!";
    }
}
  1. Reactive programming with Micronaut:
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import reactor.core.publisher.Flux;

@Controller("/reactive")
public class ReactiveController {

    @Get("/numbers")
    public Flux<Integer> getNumbers() {
        return Flux.range(1, 10);
    }
}

Getting Started

  1. Install Micronaut CLI:

    $ sdk install micronaut
    
  2. Create a new project:

    $ mn create-app my-micronaut-app
    
  3. Navigate to the project directory and run the application:

    $ cd my-micronaut-app
    $ ./gradlew run
    
  4. Access the default endpoint at http://localhost:8080

Competitor Comparisons

Spring Boot

Pros of Spring Boot

  • Extensive ecosystem and community support
  • Comprehensive documentation and learning resources
  • Wide range of production-ready starters and auto-configuration options

Cons of Spring Boot

  • Larger memory footprint and slower startup times
  • Heavier reliance on runtime reflection
  • Steeper learning curve for beginners

Code Comparison

Spring Boot:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Micronaut:

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

Both frameworks offer similar syntax for bootstrapping applications, but Micronaut's approach is more lightweight and doesn't rely on runtime reflection. Spring Boot's @SpringBootApplication annotation combines multiple annotations, while Micronaut uses a simpler @Singleton annotation.

Spring Boot's extensive ecosystem and mature documentation make it a popular choice for enterprise applications. However, Micronaut's focus on reducing memory usage and startup times makes it more suitable for microservices and serverless environments.

13,537

Quarkus: Supersonic Subatomic Java.

Pros of Quarkus

  • Faster startup time and lower memory footprint
  • Better native image support with GraalVM
  • More extensive Kubernetes and cloud-native features

Cons of Quarkus

  • Steeper learning curve for developers new to reactive programming
  • Smaller ecosystem and community compared to Micronaut
  • Less flexible in terms of customization options

Code Comparison

Quarkus:

@Path("/hello")
public class GreetingResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello from Quarkus";
    }
}

Micronaut:

@Controller("/hello")
public class GreetingController {
    @Get(produces = MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello from Micronaut";
    }
}

Both frameworks use similar annotations for defining RESTful endpoints, but Quarkus uses JAX-RS annotations while Micronaut uses its own set of annotations. The overall structure and simplicity of the code are comparable, making it easy for developers to switch between the two frameworks.

14,240

Vert.x is a tool-kit for building reactive applications on the JVM

Pros of Vert.x

  • Highly scalable and performant, designed for handling concurrent connections
  • More flexible and lightweight, allowing for fine-grained control
  • Supports multiple programming languages (polyglot)

Cons of Vert.x

  • Steeper learning curve, especially for developers new to reactive programming
  • Less opinionated, requiring more manual configuration and setup
  • Smaller ecosystem compared to Micronaut

Code Comparison

Vert.x HTTP server:

Vertx vertx = Vertx.vertx();
vertx.createHttpServer().requestHandler(req -> {
  req.response().end("Hello World!");
}).listen(8080);

Micronaut HTTP server:

@Controller("/")
public class HelloController {
    @Get
    public String index() {
        return "Hello World!";
    }
}

Vert.x focuses on a more low-level, event-driven approach, while Micronaut provides a higher-level, annotation-based programming model. Vert.x offers more flexibility but requires more boilerplate code, whereas Micronaut simplifies common tasks with its opinionated design.

7,485

A simple and modern Java and Kotlin web framework

Pros of Javalin

  • Lightweight and simple, with a minimal learning curve
  • Fast startup time and low memory footprint
  • Excellent for microservices and small to medium-sized applications

Cons of Javalin

  • Limited built-in features compared to Micronaut's extensive ecosystem
  • Less suitable for large, complex enterprise applications
  • Fewer integrations with other frameworks and libraries out of the box

Code Comparison

Javalin:

import io.javalin.Javalin;

public class HelloWorld {
    public static void main(String[] args) {
        Javalin app = Javalin.create().start(7000);
        app.get("/", ctx -> ctx.result("Hello World"));
    }
}

Micronaut:

import io.micronaut.http.annotation.*;
import io.micronaut.http.client.annotation.*;
import io.micronaut.runtime.Micronaut;

@Controller("/")
public class HelloController {
    @Get
    public String index() {
        return "Hello World";
    }

    public static void main(String[] args) {
        Micronaut.run(HelloController.class);
    }
}
3,481

Java libraries for writing microservices

Pros of Helidon

  • Built and maintained by Oracle, providing enterprise-level support and integration with Oracle Cloud
  • Offers both a lightweight microframework (Helidon SE) and a full MicroProfile implementation (Helidon MP)
  • Strong focus on reactive programming and non-blocking I/O

Cons of Helidon

  • Smaller community and ecosystem compared to Micronaut
  • Less extensive documentation and fewer third-party integrations
  • Steeper learning curve for developers new to reactive programming concepts

Code Comparison

Helidon (Reactive WebServer):

Routing.builder()
    .get("/greet", (req, res) -> res.send("Hello, World!"))
    .build();
WebServer.create(routing).start();

Micronaut (HTTP Server):

@Controller("/greet")
public class GreetingController {
    @Get
    public String greet() {
        return "Hello, World!";
    }
}

Both frameworks offer concise ways to create web endpoints, but Helidon's approach is more focused on reactive programming, while Micronaut provides a more traditional annotation-based controller style.

A damn simple library for building production-ready RESTful web services.

Pros of Dropwizard

  • Mature and battle-tested framework with a large community
  • Excellent documentation and extensive examples
  • Integrates well-established libraries like Jetty and Jersey

Cons of Dropwizard

  • Heavier footprint and slower startup times
  • Less flexible for microservices architecture
  • Limited support for reactive programming

Code Comparison

Dropwizard:

public class HelloWorldApplication extends Application<HelloWorldConfiguration> {
    public static void main(String[] args) throws Exception {
        new HelloWorldApplication().run(args);
    }
}

Micronaut:

@Singleton
public class HelloController {
    @Get("/hello")
    public String hello() {
        return "Hello World";
    }
}

Dropwizard follows a more traditional Java application structure with a main class extending Application, while Micronaut uses annotations and dependency injection for a more concise setup. Micronaut's approach is generally more suitable for microservices and serverless environments, offering faster startup times and lower memory footprint. However, Dropwizard's mature ecosystem and comprehensive documentation make it a solid choice for larger, more complex applications where performance at scale is less critical than developer productivity and established patterns.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Micronaut Framework

Build Status Revved up by Develocity Quality Gate Status

Micronaut Framework is a modern, JVM-based, full stack Java framework designed for building modular, easily testable JVM applications with support for Java, Kotlin and the Groovy language.

The Micronaut framework was originally created by a team who had also worked on the Grails framework. The Micronaut framework takes inspiration from lessons learned over the years building real-world applications from monoliths to microservices using Spring, Spring Boot and the Grails framework. The core team continues to develop and maintain the Micronaut project through the support of the Micronaut Foundation.

Micronaut Framework aims to provide all the tools necessary to build JVM applications including:

  • Dependency Injection and Inversion of Control (IoC)
  • Aspect Oriented Programming (AOP)
  • Sensible Defaults and Auto-Configuration

With Micronaut Framework you can build Message-Driven Applications, Command Line Applications, HTTP Servers and more whilst for Microservices in particular Micronaut Framework also provides:

  • Distributed Configuration
  • Service Discovery
  • HTTP Routing
  • Client-Side Load Balancing

At the same time Micronaut Framework aims to avoid the downsides of frameworks like Spring, Spring Boot and Grails by providing:

  • Fast startup time
  • Reduced memory footprint
  • Minimal use of reflection
  • Minimal use of proxies
  • No runtime bytecode generation
  • Easy Unit Testing

This is achieved by pre-computing the framework infrastructure at compilation time which reduces the logic required at runtime for the application to work.

For more information on using Micronaut Framework see the documentation at micronaut.io

Example Applications

Example Micronaut Framework applications can be found in the Examples repository

Building From Source

To build from source checkout the code and run:

./gradlew publishToMavenLocal

To build the documentation run ./gradlew docs. The documentation is built to build/docs/index.html.

Contributing Code

If you wish to contribute to the development of Micronaut Framework please read the CONTRIBUTING.md

Versioning

Micronaut Framework uses Semantic Versioning 2.0.0. To understand what that means, please see the specification documentation. Exclusions to Micronaut Framework's public API include any classes annotated with @Experimental or @Internal, which reside in the io.micronaut.core.annotation package.