In the Dubbo 3.3.0 version, we officially released the Dubbo AOT static solution. This document will introduce how to connect applications to GraalVM Native Image through Dubbo AOT technology, the process of compiling applications into native binary packages, and the components currently supported.
Due to the rapid development of Dubbo AOT technology, this document may not always be up to date. Please refer to the following content for the latest information and usage:
For more information about GraalVm, you can read the document at https://www.graalvm.org/docs/getting-started/container-images/.
Native Image Compilation: Pre-compile applications into native images to reduce startup time and memory usage.
Language Interoperability: GraalVM allows writing code in multiple languages to interoperate within the same application.
Optimization: GraalVM provides optimizations for applications written in Java, JavaScript, and other languages, enhancing the performance of Dubbo applications.
Polyglot Debugging: GraalVM can debug code written in multiple languages within the same session, which is very useful for troubleshooting issues in complex Dubbo applications.
Java Runtime: It can run on GraalVM, providing a faster, more efficient Java runtime environment.
Developing Microservices: It can be combined with GraalVM to create high-performance, low-resource-utilization microservices.
Before compiling our Dubbo project, ensure that we are based on a GraalVM environment.
This includes maven-compiler-plugin, spring-boot-maven-plugin, native-maven-plugin, and dubbo-maven-plugin. Modify the mainClass in dubbo-maven-plugin to the full path of the required startup class. (The API usage does not require adding the spring-boot-maven-plugin dependency.)
    <profiles>
        <profile>
            <id>native</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <release>17</release>
                            <fork>true</fork>
                            <verbose>true</verbose>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>process-aot</id>
                                <goals>
                                    <goal>process-aot</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>0.9.25</version>
                        <configuration>
                            <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                            <metadataRepository>
                                <enabled>true</enabled>
                            </metadataRepository>
                            <requiredVersion>22.3</requiredVersion>
                        </configuration>
                        <executions>
                            <execution>
                                <id>add-reachability-metadata</id>
                                <goals>
                                    <goal>add-reachability-metadata</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.dubbo</groupId>
                        <artifactId>dubbo-maven-plugin</artifactId>
                        <version>${dubbo.version}</version>
                        <configuration>
                            <mainClass>com.example.nativedemo.NativeDemoApplication</mainClass>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>process-sources</phase>
                                <goals>
                                    <goal>dubbo-process-aot</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
The API usage does not require adding the dubbo-config-spring6 dependency.
<dependency>
    <groupId>org.apache.dubbo</groupId>
    <artifactId>dubbo-config-spring6</artifactId>
    <version>${dubbo.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.dubbo</groupId>
    <artifactId>dubbo-native</artifactId>
    <version>${dubbo.version}</version>
</dependency>
Example configuration:
dubbo:
  application:
    name: ${spring.application.name}
    logger: slf4j
  protocol:
    name: dubbo
    port: -1
    serialization: fastjson2
  registry:
    id: zk-registry
    address: zookeeper://127.0.0.1:2181
  config-center:
    address: zookeeper://127.0.0.1:2181
  metadata-report:
    address: zookeeper://127.0.0.1:2181
  provider:
    serialization: fastjson2
  consumer:
    serialization: fastjson2
Run the following compile command in the project’s root path:
 mvn clean install -P native -Dmaven.test.skip=true
 mvn clean install -P native native:compile -Dmaven.test.skip=true
The binary file is located in the target/ directory, usually named after the project, for example, target/native-demo.
| Component Name | Required Plugin | Plugin Version | Notes | 
|---|---|---|---|
| Apache Commons Logging | native-maven-plugin | 0.9.24 and above | |
| JDK Logger | native-maven-plugin | 0.9.24 and above | |
| slf4j | spring-boot-maven-plugin | 3.x.x (latest version) | |
| Log4j | native-maven-plugin | 0.10.0 and above | |
| Log4j2 | 
| Component Name | Required Plugin | Plugin Version | Notes | 
|---|---|---|---|
| FastJson2 | dubbo-maven-plugin | 3.3.0 and above | |
| JDK | native-maven-plugin | 0.9.24 and above | |
| Hessian-Lite | Not friendly with JDK 17, unsupported for now | 
| Component Name | Required Plugin | Plugin Version | Notes | 
|---|---|---|---|
| Zookeeper | dubbo-maven-plugin | 3.3.0 | Only supports Zookeeper Curator5 | 
| Component Name | Required Plugin | Plugin Version | Notes | 
|---|---|---|---|
| Zookeeper | dubbo-maven-plugin | 3.3.0 | Only supports Zookeeper Curator5 | 
| Component Name | Required Plugin | Plugin Version | Notes | 
|---|---|---|---|
| Zookeeper | dubbo-maven-plugin | 3.3.0 | Only supports Zookeeper Curator5 | 
| Component Name | Required Plugin | Plugin Version | Notes | 
|---|---|---|---|
| Micrometer |