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 10 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
5 changes: 2 additions & 3 deletions service/service-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
<module>sample-service-reactive-oracle-book</module>
<module>sample-service-rest-book</module>
<module>sample-service-rest-cassandra-book</module>
<module>sample-service-rest-native-book</module>
<module>sample-service-rest-oracle-book</module>
</modules>



</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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

## Usage

- In the terminal run: `mvn -Pnative -DskipTests package` 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
`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.

210 changes: 121 additions & 89 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,139 @@
<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/>
<spring-native.version>0.12.1</spring-native.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>
</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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</exclusion>
<exclusion>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-framework-logging</artifactId>
</exclusion>
<exclusion>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-framework-api-docs</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>
</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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</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>
</build>
</project>
<profiles>
<profile>
<id>native</id>
<properties>
<repackage.classifier>exec</repackage.classifier>
</properties>
<dependencies>
<!-- Required with Maven Surefire 2.x -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<version>0.12.1</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
<execution>
<id>test-generate</id>
<goals>
<goal>test-generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.13</version>
<extensions>true</extensions>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
<configuration>

</configuration>
</plugin>
<!-- Avoid a clash between Spring Boot repackaging and native-maven-plugin -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>${repackage.classifier}</classifier>
<image>
<builder>paketobuildpacks/builder:tiny</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
</env>
</image>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<repositories>
<!-- ... -->
whoswendy marked this conversation as resolved.
Show resolved Hide resolved
<repository>
<id>spring-release</id>
<name>Spring release</name>
<url>https://repo.spring.io/release</url>
</repository>
</repositories>
<pluginRepositories>
<!-- ... -->
whoswendy marked this conversation as resolved.
Show resolved Hide resolved
<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,13 +13,16 @@
*/
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;
import org.springframework.nativex.hint.TypeHint;

/**
* BookApplication starts the Spring Boot Application for the book rest sample.
* {@link BookApplication} starts the Spring Boot Application.
*/
@TypeHint(types = {ReadBookRequest.class, ReadBookResponse.class})
@SpringBootApplication
public class BookApplication {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.americanexpress.service.book.rest.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
* {@link BookConfig} is the configuration class for the Book Application.
*/
@Configuration
@PropertySource("classpath:/service-book-application.properties")
@ComponentScan(basePackages = "io.americanexpress.service.book.rest")
public class BookConfig {

public static final String BOOK_ENDPOINT = "/v1/books";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.americanexpress.service.book.rest.controller;

import io.americanexpress.service.book.rest.config.BookConfig;
import io.americanexpress.service.book.rest.model.ReadBookRequest;
import io.americanexpress.service.book.rest.model.ReadBookResponse;
import io.americanexpress.service.book.rest.service.ReadBookService;
import io.americanexpress.synapse.service.rest.controller.BaseReadMonoController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* {@link ReadBookController} is the controller for /v1/books/inquiry_results
*/
@RestController
@RequestMapping(BookConfig.BOOK_ENDPOINT)
public class ReadBookController extends BaseReadMonoController<ReadBookRequest, ReadBookResponse, ReadBookService> {
}
Loading