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

Add spring boot3 support #1742

Merged
merged 6 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ jobs:
run: |
./mvnw -V clean install -f ci.ant --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false
./mvnw -V clean install -f ci.common --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false
# Run tests that require Java 17 or later
- name: Run tests that require Java 17 or later
if: ${{ matrix.java == '17' }}
run: ./mvnw -V verify --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false -Ponline-its -D"invoker.streamLogsOnFailures"=true -D"invoker.test"="*setup*,*springboot-3-*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}"
# Run tests
- name: Run tests
run: ./mvnw -V verify --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false -Ponline-its -D"invoker.streamLogsOnFailures"=true -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}"
Expand Down Expand Up @@ -112,6 +116,10 @@ jobs:
- name: Install ci.common
working-directory: C:/ci.common
run: .\mvnw.cmd -V clean install --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false
# Run tests that require Java 17 or later
- name: Run tests that require Java 17 or later
if: ${{ matrix.java == '17' }}
run: .\mvnw.cmd -V verify -Ponline-its --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false -D"invoker.streamLogsOnFailures"=true -D"invoker.test"="*setup*,*springboot-3-*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}"
# Run tests
- name: Run tests
working-directory: C:/ci.maven
Expand Down
7 changes: 6 additions & 1 deletion docs/spring-boot-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ The `server.xml` provided by the `serverXmlFile` parameter or located in the `co
| Feature | Description |
| ------- | ----------- |
| springBoot-1.5 | Required to support applications with Spring Boot version 1.5.x. |
| springBoot-2.0 | Required to support applications with Spring Boot version 2.0.x and above. |
| springBoot-2.0 | Required to support applications with Spring Boot version 2.0.x. |
| springBoot-3.0 | Required to support applications with Spring Boot version 3.x. |

The Liberty features that support the Spring Boot starters can be found [here](https://www.ibm.com/support/knowledgecenter/SSAW57_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/rwlp_springboot.html). They should be enabled in the `server.xml` along with the appropriate Spring Boot feature.

### Java Support

The Spring Boot version 3.x requires Java 17 or above.

### Example

To use the `liberty-maven-plugin` to install a Spring Boot application packaged as a Spring Boot Uber JAR, include the appropriate XML in the `plugins` section of your `pom.xml`.
Expand Down
4 changes: 4 additions & 0 deletions liberty-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
<configuration>
<pomExcludes>
<pomExclude>binary-scanner-it/pom.xml</pomExclude>
<pomExclude>springboot-3-tests/pom.xml</pomExclude>
<pomExclude>dev-container-it/pom.xml</pomExclude>
</pomExcludes>
</configuration>
Expand Down Expand Up @@ -263,6 +264,7 @@
<pomExclude>server-param-configdir-not-override-it/pom.xml</pomExclude>
<pomExclude>install-features-it/pom.xml</pomExclude>
<pomExclude>binary-scanner-it/pom.xml</pomExclude>
<pomExclude>springboot-3-tests/pom.xml</pomExclude>
<pomExclude>dev-container-it/pom.xml</pomExclude>
</pomExcludes>
</configuration>
Expand Down Expand Up @@ -303,6 +305,7 @@
<pomExclude>dev-container-it/pom.xml</pomExclude>
<pomExclude>generate-features-it/pom.xml</pomExclude>
<pomExclude>binary-scanner-it/pom.xml</pomExclude>
<pomExclude>springboot-3-tests/pom.xml</pomExclude>
</pomExcludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -347,6 +350,7 @@
<pomExclude>install-features-it/pom.xml</pomExclude>
<pomExclude>generate-features-it/pom.xml</pomExclude>
<pomExclude>binary-scanner-it/pom.xml</pomExclude>
<pomExclude>springboot-3-tests/pom.xml</pomExclude>
</pomExcludes>
</configuration>
</plugin>
Expand Down
30 changes: 30 additions & 0 deletions liberty-maven-plugin/src/it/springboot-3-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.openliberty.tools.it</groupId>
<artifactId>tests</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>springboot-3-tests</artifactId>
<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<modules>
<module>springboot-3-appsdirectory-apps-it</module>
<module>springboot-3-appsdirectory-dropins-it</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>springboot-3-appsdirectory-apps-it</artifactId>
<version>1.0.0.Final</version>
<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- Support for JDK 9 and above-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- Test support for classifier configuration parameter -->
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>

<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>@pom.version@</version>

<!-- Specify configuration, executions for liberty-maven-plugin -->
<configuration>
<serverName>test</serverName>
<serverXmlFile>src/test/resources/server.xml</serverXmlFile>
<runtimeArtifact>
<groupId>com.ibm.websphere.appserver.runtime</groupId>
<artifactId>wlp-jakartaee10</artifactId>
<version>23.0.0.10</version>
<type>zip</type>
</runtimeArtifact>
<appsDirectory>apps</appsDirectory>
<deployPackages>spring-boot-project</deployPackages>
</configuration>

<executions>
<execution>
<id>stop-server-before-clean</id>
<phase>pre-clean</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<id>create-server</id>
<phase>prepare-package</phase>
<goals>
<goal>install-server</goal>
<goal>create</goal>
<goal>install-feature</goal>
</goals>
</execution>
<execution>
<id>install-apps</id>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>test-start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>test-start</goal>
</goals>
</execution>
<execution>
<id>test-stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>test-stop</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<runOrder>alphabetical</runOrder>
</configuration>
<executions>
<execution>
<id>default-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>default-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* (C) Copyright IBM Corporation 2023.
*
* 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 application;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RequestMapping("/spring")
public String hello() {
return "HELLO SPRING BOOT!!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* (C) Copyright IBM Corporation 2023.
*
* 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 application;

import static org.junit.Assert.*;

import java.io.File;
import org.junit.Test;

public class InstallSpringBoot30AppIT {

@Test
public void testThinApplicationExistsInAppsDirectory() throws Exception {

File f = new File("target/liberty/wlp/usr/servers/test/apps/thin-springboot-3-appsdirectory-apps-it-1.0.0.Final-exec.jar");
assertTrue(f.getCanonicalFile() + " doesn't exist. Plugin failed to place the file at right destination.", f.exists());
}

@Test
public void testLibIndexCacheExists() throws Exception {
File f = new File("target/liberty/wlp/usr/shared/resources/lib.index.cache");
assertTrue(f.getCanonicalFile()+ " doesn't exist. Plugin failed to place the cache directory at right destination.", f.exists());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* (C) Copyright IBM Corporation 2023.
*
* 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 application;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.junit.Test;

public class SpringBoot30RestEndpointIT {

@Test
public void testSpringRestBootEndpoint() throws Exception {

URL requestUrl = new URL("http://localhost:9080/spring/");
HttpURLConnection conn = (HttpURLConnection) requestUrl.openConnection();

if (conn != null) {
assertEquals("Expected response code not found.", 200, conn.getResponseCode());
}

StringBuffer response = new StringBuffer();

try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
String line;
while ((line = in.readLine()) != null) {
response.append(line);
}
}
assertEquals("Expected body not found.", "HELLO SPRING BOOT!!", response.toString());
}
}
Loading