Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/spring native sample #217

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -898,19 +898,6 @@
<version>3.3.4</version>
</dependency>

<!--Spring Native-->
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>${spring-native.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot</artifactId>
<version>${spring-native.version}</version>
<scope>provided</scope>
</dependency>

<!--Springdoc-->
<dependency>
<groupId>org.springdoc</groupId>
Expand Down Expand Up @@ -1284,42 +1271,6 @@
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>

<!--Native Plugins-->
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<version>${spring-native.version}</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>21.2.0</version>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-plugin.version}</version>
<configuration>
</configuration>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down
1 change: 1 addition & 0 deletions service/service-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<module>sample-service-rest-book</module>
<module>sample-service-rest-cassandra-book</module>
<module>sample-service-rest-mysql-book</module>
<module>sample-service-rest-native-book</module>
<module>sample-service-rest-oracle-book</module>
<module>sample-service-rest-postgres-book</module>
</modules>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# sample-service-rest-native-book

## Description

- This is a sample module demonstrating creating a GraalVM Native Application using Spring Native and Synapse Service Rest.
- Status: experimental

## Requirements
Please refer to https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#getting-started-native-image-system-requirements
- Local instance of MongoDB running (reference to module sample-data-mongodb-book)

## Usage

- In the terminal run: `mvn -Pnative native:compile` which performs the AOT (ahead-of-time) transformations required and build the native image.
- If successful, the generated executable `sample-service-rest-native-book` will show up in the `target` directory.
- To run the executable, in the terminal run: `target/sample-service-rest-native-book`

### Sample Request
#### Create
`POST localhost:8080/v1/books`
```json
{
"title": "Alice In Wonderland",
"author": "Lewis Carroll"
}
```
#### Read
`POST localhost:8080/v1/books/inquiry_results`
```json
{
"title": "Alice In Wonderland",
"author": "Lewis Carroll"
}
```

## Resources
- https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#getting-started-native-build-tools

This file was deleted.

231 changes: 144 additions & 87 deletions service/service-samples/sample-service-rest-native-book/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,107 +24,164 @@
<artifactId>sample-service-rest-native-book</artifactId>

<properties>
<!-- This property is needed to prevent a conflict between various build plugins -->
<classifier/>

<!-- Specify main class to allow your native-image-maven-plugin to find it -->
<main.class>io.americanexpress.service.book.rest.BookApplication</main.class>

<!-- This specifies the build pack to be used in your generated cloud image. -->
<!-- Valid options are tiny, base, full -->
<builder>paketobuildpacks/builder:base</builder>

<!-- You can add additional native build arguments with this property -->
<native.build.args/>
<repackage.classifier/>
<native-build-tools-plugin.version>0.9.17</native-build-tools-plugin.version>
</properties>

<!--Dependencies-->
<dependencies>
<!--Synapse-->
<!-- <dependency>-->
<!-- <groupId>io.americanexpress.synapse</groupId>-->
<!-- <artifactId>synapse-service-rest</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot</artifactId>
<scope>provided</scope>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>sample-data-mongodb-book</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-web</artifactId>
<version>3.2.7</version>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-service-rest</artifactId>
<exclusions>
<exclusion>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-framework-api-docs</artifactId>
</exclusion>
<exclusion>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-framework-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
whoswendy marked this conversation as resolved.
Show resolved Hide resolved
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>0.12.1</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.4</version>
<type>pom</type>
<scope>import</scope>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<!--Build Docker Image-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
<image>
<builder>${builder}</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>${native.build.args}</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
</image>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<configuration>
<removeSpelSupport>true</removeSpelSupport>
<removeXmlSupport>true</removeXmlSupport>
</configuration>
<executions>
<execution>
<id>test-generate</id>
<goals>
<goal>test-generate</goal>
</goals>
</execution>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<configuration>
<mainClass>${main.class}</mainClass>
<imageName>${project.artifactId}</imageName>
<buildArgs>${native.build.args}</buildArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-build-tools-plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder:tiny</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
</env>
</image>
</configuration>
<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>
<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>
</plugins>
</build>
</profile>
<profile>
<id>nativeTest</id>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-test-aot</id>
<goals>
<goal>process-test-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
<requiredVersion>22.3</requiredVersion>
</configuration>
<executions>
<execution>
<id>native-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<repositories>
<repository>
<id>spring-release</id>
<name>Spring release</name>
<url>https://repo.spring.io/release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-release</id>
<name>Spring release</name>
<url>https://repo.spring.io/release</url>
</pluginRepository>
</pluginRepositories>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
*/
package io.americanexpress.service.book.rest;


import io.americanexpress.service.book.rest.model.ReadBookRequest;
import io.americanexpress.service.book.rest.model.ReadBookResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* BookApplication starts the Spring Boot Application for the book rest sample.
* {@link BookApplication} starts the Spring Boot Application.
*/
@SpringBootApplication
public class BookApplication {
Expand Down
Loading