Skip to content

Commit 2e8d487

Browse files
authored
Merge pull request #139 from OpenLiberty/staging
Merge staging to prod - Update the guide to use Springboot 3.1.3 (#136)
2 parents 6c98efa + cff8936 commit 2e8d487

File tree

23 files changed

+290
-354
lines changed

23 files changed

+290
-354
lines changed

Diff for: .github/workflows/test.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
env:
2828
VALIDATE_ALL_CODEBASE: false
2929
VALIDATE_BASH: false
30+
VALIDATE_JAVA: false
3031
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3132
LINTER_RULES_PATH: ./tools/pr-checker/linters/
3233
DEFAULT_BRANCH: prod
@@ -46,14 +47,15 @@ jobs:
4647
working-directory: finish
4748

4849
steps:
49-
- uses: actions/checkout@v2
50-
- name: Set up JDK 8
51-
uses: actions/setup-java@v1
50+
- uses: actions/checkout@v4
51+
- name: Set up JDK 17
52+
uses: actions/setup-java@v3
5253
with:
53-
java-version: 8
54+
distribution: 'semeru'
55+
java-version: 17
5456
- run: unset _JAVA_OPTIONS
5557
- name: Run tests
56-
run: sudo ../scripts/testApp.sh
58+
run: sudo -E ../scripts/testApp.sh
5759
- name: Post tests
5860
if: always()
5961
run: |

Diff for: README.adoc

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:projectid: spring-boot
1111
:page-duration: 20 minutes
1212
:page-releasedate: 2019-11-04
13+
:page-majorupdateddate: 2023-11-15
1314
:page-description: Learn how to containerize, package, and run a Spring Boot application on Open Liberty.
1415
:page-tags: ['Docker']
1516
:page-related-guides: ['rest-intro', 'containerize']
@@ -28,7 +29,7 @@ Learn how to containerize, package, and run a Spring Boot application on Open Li
2829

2930
== What you'll learn
3031

31-
The starting point of this guide is the finished application from the https://spring.io/guides/gs/spring-boot/[Building an Application with Spring Boot^] guide. If you are not familiar with Spring Boot, complete that guide first. Java 8 is required to run this project.
32+
The starting point of this guide is the finished application from the https://spring.io/guides/gs/spring-boot/[Building an Application with Spring Boot^] guide. If you are not familiar with Spring Boot, complete that guide first. Java 17 is required to run this project.
3233

3334
You will learn how to use the `springBootUtility` command to deploy a Spring Boot application in Docker on Open Liberty without modification. This command stores the dependent library JAR files of the application to the target library cache, and packages the remaining application artifacts into a thin application JAR file.
3435

@@ -69,10 +70,15 @@ You can now run the application in the embedded Tomcat web container by executin
6970
java -jar target/guide-spring-boot-0.1.0.jar
7071
```
7172

72-
Notice that the console output displays a message about the application running in Tomcat on port `8080`.
73+
After you see the following messages, the application is ready:
7374
[role='no_copy']
7475
----
75-
... INFO ... [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
76+
... INFO ... [ main] com.example.springboot.Application : Started Application in 2.511 seconds (process running for 3.24)
77+
Let's inspect the beans provided by Spring Boot:
78+
application
79+
...
80+
welcomePageHandlerMapping
81+
welcomePageNotAcceptableHandlerMapping
7682
----
7783

7884
// Static guide instruction

Diff for: finish/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stage and thin the application
22
# tag::OLimage1[]
3-
FROM icr.io/appcafe/open-liberty:full-java8-openj9-ubi as staging
3+
FROM icr.io/appcafe/open-liberty:full-java17-openj9-ubi as staging
44
# end::OLimage1[]
55

66
# tag::copyJar[]
@@ -17,7 +17,7 @@ RUN springBootUtility thin \
1717

1818
# Build the image
1919
# tag::OLimage2[]
20-
FROM icr.io/appcafe/open-liberty:kernel-slim-java8-openj9-ubi
20+
FROM icr.io/appcafe/open-liberty:kernel-slim-java17-openj9-ubi
2121
# end::OLimage2[]
2222

2323
ARG VERSION=1.0
@@ -37,7 +37,7 @@ LABEL \
3737
description="This image contains the hello application running with the Open Liberty runtime."
3838

3939
# tag::serverXml[]
40-
RUN cp /opt/ol/wlp/templates/servers/springBoot2/server.xml /config/server.xml
40+
RUN cp /opt/ol/wlp/templates/servers/springBoot3/server.xml /config/server.xml
4141
# end::serverXml[]
4242

4343
RUN features.sh

Diff for: finish/pom.xml

+42-64
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,54 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
3-
<modelVersion>4.0.0</modelVersion>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.1.0</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example</groupId>
12+
<artifactId>guide-spring-boot</artifactId>
13+
<version>0.1.0</version>
14+
<name>spring-boot-complete</name>
15+
<description>Demo project for Spring Boot</description>
416

5-
<groupId>org.springframework</groupId>
6-
<artifactId>guide-spring-boot</artifactId>
7-
<version>0.1.0</version>
17+
<properties>
18+
<java.version>17</java.version>
19+
</properties>
820

9-
<parent>
10-
<groupId>org.springframework.boot</groupId>
11-
<artifactId>spring-boot-starter-parent</artifactId>
12-
<version>2.6.6</version>
13-
</parent>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
1426

15-
<dependencies>
16-
<dependency>
17-
<groupId>org.springframework.boot</groupId>
18-
<artifactId>spring-boot-starter-web</artifactId>
19-
</dependency>
20-
<!-- tag::actuator[] -->
21-
<dependency>
22-
<groupId>org.springframework.boot</groupId>
23-
<artifactId>spring-boot-starter-actuator</artifactId>
24-
</dependency>
25-
<!-- end::actuator[] -->
26-
<!-- tag::tests[] -->
27-
<dependency>
28-
<groupId>org.springframework.boot</groupId>
29-
<artifactId>spring-boot-starter-test</artifactId>
30-
<scope>test</scope>
31-
</dependency>
32-
<dependency>
33-
<groupId>org.junit.vintage</groupId>
34-
<artifactId>junit-vintage-engine</artifactId>
35-
<scope>test</scope>
36-
<exclusions>
37-
<exclusion>
38-
<groupId>org.hamcrest</groupId>
39-
<artifactId>hamcrest-core</artifactId>
40-
</exclusion>
41-
</exclusions>
42-
</dependency>
43-
<!-- end::tests[] -->
44-
</dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-actuator</artifactId>
30+
</dependency>
4531

46-
<properties>
47-
<java.version>1.8</java.version>
48-
</properties>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-test</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
</dependencies>
4938

50-
<build>
51-
<plugins>
52-
<plugin>
53-
<groupId>org.springframework.boot</groupId>
54-
<artifactId>spring-boot-maven-plugin</artifactId>
55-
</plugin>
56-
<plugin>
57-
<artifactId>maven-failsafe-plugin</artifactId>
58-
<version>2.22.2</version>
59-
<executions>
60-
<execution>
61-
<goals>
62-
<goal>integration-test</goal>
63-
<goal>verify</goal>
64-
</goals>
65-
</execution>
66-
</executions>
67-
</plugin>
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-maven-plugin</artifactId>
44+
</plugin>
6845

6946
<!-- Enable Liberty Maven plugin -->
7047
<!-- tag::libertyMavenPlugin[] -->
7148
<plugin>
7249
<groupId>io.openliberty.tools</groupId>
7350
<artifactId>liberty-maven-plugin</artifactId>
74-
<version>3.8.2</version>
51+
<version>3.9</version>
7552
<configuration>
7653
<!-- tag::appsDirectory[] -->
7754
<appsDirectory>apps</appsDirectory>
@@ -104,6 +81,7 @@
10481
<!-- end::libertyMavenPlugin[] -->
10582
<!-- End of Liberty Maven plugin -->
10683

107-
</plugins>
108-
</build>
84+
</plugins>
85+
</build>
86+
10987
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.example.springboot;
2+
3+
import java.util.Arrays;
4+
5+
import org.springframework.boot.CommandLineRunner;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.ApplicationContext;
9+
import org.springframework.context.annotation.Bean;
10+
11+
@SpringBootApplication
12+
public class Application {
13+
14+
public static void main(String[] args) {
15+
SpringApplication.run(Application.class, args);
16+
}
17+
18+
@Bean
19+
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
20+
return args -> {
21+
22+
System.out.println("Let's inspect the beans provided by Spring Boot:");
23+
24+
String[] beanNames = ctx.getBeanDefinitionNames();
25+
Arrays.sort(beanNames);
26+
for (String beanName : beanNames) {
27+
System.out.println(beanName);
28+
}
29+
30+
};
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.springboot;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
public class HelloController {
8+
9+
@GetMapping("/hello")
10+
public String index() {
11+
return "Greetings from Spring Boot!";
12+
}
13+
14+
}

Diff for: finish/src/main/java/hello/Application.java

-33
This file was deleted.

Diff for: finish/src/main/java/hello/HelloController.java

-14
This file was deleted.

Diff for: finish/src/main/liberty/config/server.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
<featureManager>
55
<!-- tag::servlet[] -->
6-
<feature>servlet-4.0</feature>
6+
<feature>servlet-6.0</feature>
77
<!-- end::servlet[] -->
88
<!-- tag::springboot[] -->
9-
<feature>springBoot-2.0</feature>
9+
<feature>springBoot-3.0</feature>
1010
<!-- end::springboot[] -->
1111
</featureManager>
1212

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.example.springboot;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.boot.test.web.client.TestRestTemplate;
8+
import org.springframework.http.ResponseEntity;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
13+
public class HelloControllerIT {
14+
15+
@Autowired
16+
private TestRestTemplate template;
17+
18+
@Test
19+
public void getHello() throws Exception {
20+
ResponseEntity<String> response = template.getForEntity("/hello", String.class);
21+
assertThat(response.getBody()).isEqualTo("Greetings from Spring Boot!");
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
package hello;
1+
package com.example.springboot;
22

33
import static org.hamcrest.Matchers.equalTo;
44
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
55
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
66

7-
import org.junit.Test;
8-
import org.junit.runner.RunWith;
7+
import org.junit.jupiter.api.Test;
8+
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
1111
import org.springframework.boot.test.context.SpringBootTest;
1212
import org.springframework.http.MediaType;
13-
import org.springframework.test.context.junit4.SpringRunner;
1413
import org.springframework.test.web.servlet.MockMvc;
1514
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
1615

17-
@RunWith(SpringRunner.class)
1816
@SpringBootTest
1917
@AutoConfigureMockMvc
2018
public class HelloControllerTest {
2119

22-
@Autowired
23-
private MockMvc mvc;
20+
@Autowired
21+
private MockMvc mvc;
2422

25-
@Test
26-
public void getHello() throws Exception {
27-
mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
28-
.andExpect(status().isOk())
29-
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
30-
}
23+
@Test
24+
public void getHello() throws Exception {
25+
mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
26+
.andExpect(status().isOk())
27+
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
28+
}
3129
}

0 commit comments

Comments
 (0)