Skip to content

Commit

Permalink
Update springboot templates to Spring Boot 3.0
Browse files Browse the repository at this point in the history
- add needed buildEnv properties
- add class to register runtime hints for MessageUtils.MessageStructureWithCaseInsensitiveHeaderKeys
- update README files

Signed-off-by: Thomas Risberg <trisberg@pivotal.io>
  • Loading branch information
trisberg committed Jan 19, 2023
1 parent 132d049 commit e407742
Show file tree
Hide file tree
Showing 9 changed files with 6,663 additions and 6,821 deletions.
4 changes: 2 additions & 2 deletions docs/reference/func_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ EXAMPLES

o Build a function container using an explicit image name, ignoring registry
and function name.
$ func build --image registry.example.com/alice/f:latest
$ func build --image registry.example.com/alice/f:latest

o Rebuild a function using prior values to determine container name.
$ func build
Expand All @@ -44,7 +44,7 @@ EXAMPLES

o Build a function specifying the Pack builder with a custom Buildpack
builder image.
$ func build --builder=pack --builder-image=cnbs/sample-builder:bionic
$ func build --builder=pack --builder-image=cnbs/sample-builder:bionic



Expand Down
4 changes: 2 additions & 2 deletions docs/reference/func_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SYNOPSIS
DESCRIPTION
Creates a new function project.

$ func create -l node -t http
$ func create -l node

Creates a function in the current directory '.' which is written in the
language/runtime 'node' and handles HTTP events.
Expand All @@ -24,7 +24,7 @@ DESCRIPTION
the path if necessary.

To complete this command interactively, use --confirm (-c):
$ func create -c
$ func create -c

Available Language Runtimes and Templates:
Language Template
Expand Down
14 changes: 12 additions & 2 deletions templates/springboot/cloudevents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This sample project contains a single function based on Spring Cloud Function: `

## Local execution

Make sure that `Java 11 SDK` is installed.
Make sure that `Java 17 SDK` is installed since Spring Boot 3.0 requires Java 17.

To start server locally run `./mvnw spring-boot:run`.
The command starts http server and automatically watches for changes of source code.
Expand Down Expand Up @@ -35,14 +35,24 @@ func build -v # build image
```

**Note**: If you want to enable the native build, you need to edit the `func.yaml` file and
set the following BuilderEnv variable:
set the `BP_NATIVE_IMAGE` BuilderEnv variable to true:

```yaml
buildEnvs:
- name: BP_NATIVE_IMAGE
value: "true"
```
**Note**: If you have issues with the [Spring AOT](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#core.aot) processing in your build, you can turn this off by editing the `func.yaml` file and remove the `-Pnative` profile from the `BP_MAVEN_BUILD_ARGUMENTS` BuilderEnv variable:

```yaml
buildEnvs:
- name: BP_MAVEN_BUILD_ARGUMENTS
value: -Pnative -Dmaven.test.skip=true --no-transfer-progress package
```

> Removing the `-Pnative` profile means that you no longer will be able to build as a native image.

### Running

This command runs the func locally in a container
Expand Down
112 changes: 9 additions & 103 deletions templates/springboot/cloudevents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<version>3.0.1</version>
<relativePath/>
</parent>

Expand All @@ -17,13 +17,12 @@
<description>A Spring Cloud Function, using Cloud Events</description>

<properties>
<java.version>11</java.version>
<spring-cloud.version>2021.0.5</spring-cloud.version>
<spring-native.version>0.12.2</spring-native.version>
<java.version>17</java.version>
<spring-cloud.version>2022.0.0</spring-cloud.version>
<compiler-plugin.version>3.10.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down Expand Up @@ -53,11 +52,6 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-function-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>${spring-native.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -68,101 +62,13 @@
<build>
<plugins>
<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>false</BP_NATIVE_IMAGE>
</env>
</image>
</configuration>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<version>${spring-native.version}</version>
<executions>
<execution>
<id>test-generate</id>
<goals>
<goal>test-generate</goal>
</goals>
</execution>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<profiles>
<profile>
<id>native</id>
<properties>
<repackage.classifier>exec</repackage.classifier>
<native-buildtools.version>0.9.12</native-buildtools.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-buildtools.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>test-native</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
<execution>
<id>build-native</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package echo;

import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.function.context.message.MessageUtils;
import org.springframework.context.annotation.ImportRuntimeHints;

@SpringBootApplication
@ImportRuntimeHints(SpringCloudEventsApplication.MessageHeaderHints.class)
public class SpringCloudEventsApplication {

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

static class MessageHeaderHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.reflection().registerType(MessageUtils.MessageStructureWithCaseInsensitiveHeaderKeys.class,
MemberCategory.INVOKE_PUBLIC_METHODS);
}
}
}
14 changes: 12 additions & 2 deletions templates/springboot/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This sample project contains a single function based on Spring Cloud Function: `

## Local execution

Make sure that `Java 11 SDK` is installed.
Make sure that `Java 17 SDK` is installed since Spring Boot 3.0 requires Java 17.

To start server locally run `./mvnw spring-boot:run`.
The command starts http server and automatically watches for changes of source code.
Expand Down Expand Up @@ -35,14 +35,24 @@ func build -v # build image
```

**Note**: If you want to enable the native build, you need to edit the `func.yaml` file and
set the following BuilderEnv variable:
set the `BP_NATIVE_IMAGE` BuilderEnv variable to true:

```yaml
buildEnvs:
- name: BP_NATIVE_IMAGE
value: "true"
```
**Note**: If you have issues with the [Spring AOT](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#core.aot) processing in your build, you can turn this off by editing the `func.yaml` file and remove the `-Pnative` profile from the `BP_MAVEN_BUILD_ARGUMENTS` BuilderEnv variable:

```yaml
buildEnvs:
- name: BP_MAVEN_BUILD_ARGUMENTS
value: -Pnative -Dmaven.test.skip=true --no-transfer-progress package
```

> Removing the `-Pnative` profile means that you no longer will be able to build as a native image.

### Running

This command runs the func locally in a container
Expand Down
Loading

0 comments on commit e407742

Please sign in to comment.