Skip to content

Commit 11f19e9

Browse files
authored
Update Spring CLI (#170)
1 parent 945ea3d commit 11f19e9

File tree

24 files changed

+349
-184
lines changed

24 files changed

+349
-184
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ build/
4242
.run
4343
target/
4444
Thumbs.db
45+
run-app.sh

database/spring-cli/catalog/project-catalog.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Binary file not shown.

database/spring-cli/projects/obaas/.mvn/wrapper/maven-wrapper.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.

database/spring-cli/projects/obaas/README.adoc

Lines changed: 0 additions & 72 deletions
This file was deleted.

database/spring-cli/projects/obaas/src/main/java/com/example/restservice/greeting/Greeting.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

database/spring-cli/projects/obaas/src/test/java/com/example/restservice/greeting/GreetingControllerTests.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

spring-cli/README .md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Spring CLI integration
2+
3+
Spring CLI integration with a project catalog to help you create Spring Boot projects using Oracle and [Oracle Backend for Microservices and AI](https://bit.ly/OracleAI-microservices).
4+
5+
## Install Spring CLI
6+
7+
The goal of the Spring CLI is to increase your productivity when you create new projects and when you add functionality to existing projects. [Spring CLI documentation](https://docs.spring.io/spring-cli/reference/index.html) describes how to install the CLI on various platforms.
8+
9+
## Add to Spring CLI
10+
11+
Execute the following command to add the `project-catalog` for [Oracle Backend for Microservices and AI](https://bit.ly/OracleAI-microservices).
12+
13+
```shell
14+
spring project-catalog add --name obaas --url https://github.com/oracle/spring-cloud-oracle/tree/main/spring-cli/catalog
15+
```
16+
17+
The Spring CLI is now aware of the [Oracle Backend for Microservices and AI](https://bit.ly/OracleAI-microservices) integration.
18+
19+
## Create project
20+
21+
To create a new project use the following command (there are more options available):
22+
23+
```shell
24+
spring boot new --from obaas --name myproject
25+
```
26+
27+
## Run the Spring CLI application locally
28+
29+
To run the application locally you need access to an Oracle Database (remotely or locally). Create a shell script with the following content called `run-app.sh` and set the values for the variables to reflect your environment.
30+
31+
```shell
32+
#!/bin/bash
33+
export spring_datasource_url=<URL to database>
34+
export liquibase_datasource_username=<Liquibase database user>
35+
export liquibase_datasource_password=<Liquibase database user password>
36+
export spring_datasource_username=<Application database user>
37+
export spring_datasource_password=<Application database user password>
38+
export otel_exporter_otlp_endpoint=http://localhost:8080 # Dummy URL
39+
./mvnw spring-boot:run -Dspring-boot.run.profiles=local
40+
```
41+
42+
The Spring profile `local` turns off Eureka discovery and OTLP tracing.
43+
44+
Execute the shell script running the following command:
45+
46+
```shell
47+
source run-app.sh
48+
```
49+
50+
You can see a few `WARNINGS` with this message which can be ignored:
51+
52+
```log
53+
WARNING:
54+
55+
Liquibase detected the following invalid LIQUIBASE_* environment variables:
56+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
project-repositories:
3+
- name: "obaas"
4+
description: "RESTful Greeting service for Oracle Backend Microservices and AI"
5+
url: "https://github.com/oracle/spring-cloud-oci/tree/main/spring-cli/projects/obaas"
6+
tags:
7+
- "obaas"
8+
- "java-17"
9+
- "rest"
10+
- "web"
11+
- "boot-3.4.x"

spring-cli/projects/obaas/README.adoc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
== Basic Spring Web Application for Oracle Backend for Spring Boot and Microservices
2+
3+
This project contains a web service that can be deployed on link:https://bit.ly/OracleAI-microservices[Oracle Backend for Microservices and AI] and includes configuration for the well-known endpoints provided by the platform. The web service will accept HTTP GET requests at `http://localhost:8080/greeting`.
4+
5+
It will respond with a JSON representation of a greeting, as the following listing shows:
6+
7+
====
8+
[source,json]
9+
----
10+
{"id":1,"content":"Hello, World!"}
11+
----
12+
====
13+
14+
You can customize the greeting with an optional `name` parameter in the query string, as the following listing shows:
15+
16+
====
17+
[source,text]
18+
----
19+
http://localhost:8080/greeting?name=User
20+
----
21+
====
22+
23+
The `name` parameter value overrides the default value of `World` and is reflected in the response, as the following listing shows:
24+
25+
====
26+
[source,json]
27+
----
28+
{"id":1,"content":"Hello, User!"}
29+
----
30+
====
31+
32+
=== Building and running locally
33+
34+
[source,bash]
35+
----
36+
./mvnw spring-boot:run -Dspring-boot.run.profiles=local
37+
----
38+
39+
Then access the endpoint
40+
41+
[source,bash]
42+
----
43+
curl http://localhost:8080/greeting?name=User
44+
----
45+
46+
== About the sample code
47+
48+
The link:./pom.xml[Maven POM file] contains dependencies for commonly used features. You should review the POM file and remove any dependencies that you do not need.
49+
Note that there may be dependency configuration in the link:./src/main/resources/application.yaml[Spring application configuration file] as well, which you should remove if you remove the matching dependency.
50+
51+
The link:./src/main/resources/application.yaml[Spring application configuration file] contains comments that explain what the various configuration included is for. You can use this as an example starting point and modify it to suit your needs.
52+
53+
There are example link:./src/main/resources/db/changelog[Liquibase] configuration files provided. If you want to use Liquibase, you will need to modify these to meet your needs. Note that the use of Liquibase is optional. If you do not wish to use Liquibase you can safely remove the `src/main/resources/db` directory, the Liquibase dependency in the POM, the Liquibase build plugin in the POM, and the Liquibase configuration in the Spring application configuration file.
54+
55+
This example uses Oracle Universal Connection Pool (UCP) and also includes the dependencies for Oracle Wallet authentication and mTLS. These are optional. If you prefer to use HikariCP, you can remove the dependencies from the POM and the `oracleucp` section in the datasource configuration in the Spring application configuration file.

0 commit comments

Comments
 (0)