Skip to content

Update Spring CLI #170

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

Merged
merged 12 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ build/
.run
target/
Thumbs.db
run-app.sh
11 changes: 0 additions & 11 deletions database/spring-cli/catalog/project-catalog.yml

This file was deleted.

Binary file not shown.

This file was deleted.

72 changes: 0 additions & 72 deletions database/spring-cli/projects/obaas/README.adoc

This file was deleted.

This file was deleted.

This file was deleted.

56 changes: 56 additions & 0 deletions spring-cli/README .md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Spring CLI integration

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).

## Install Spring CLI

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.

## Add to Spring CLI

Execute the following command to add the `project-catalog` for [Oracle Backend for Microservices and AI](https://bit.ly/OracleAI-microservices).

```shell
spring project-catalog add --name obaas --url https://github.com/oracle/spring-cloud-oracle/tree/main/spring-cli/catalog
```

The Spring CLI is now aware of the [Oracle Backend for Microservices and AI](https://bit.ly/OracleAI-microservices) integration.

## Create project

To create a new project use the following command (there are more options available):

```shell
spring boot new --from obaas --name myproject
```

## Run the Spring CLI application locally

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.

```shell
#!/bin/bash
export spring_datasource_url=<URL to database>
export liquibase_datasource_username=<Liquibase database user>
export liquibase_datasource_password=<Liquibase database user password>
export spring_datasource_username=<Application database user>
export spring_datasource_password=<Application database user password>
export otel_exporter_otlp_endpoint=http://localhost:8080 # Dummy URL
./mvnw spring-boot:run -Dspring-boot.run.profiles=local
```

The Spring profile `local` turns off Eureka discovery and OTLP tracing.

Execute the shell script running the following command:

```shell
source run-app.sh
```

You can see a few `WARNINGS` with this message which can be ignored:

```log
WARNING:

Liquibase detected the following invalid LIQUIBASE_* environment variables:
```
11 changes: 11 additions & 0 deletions spring-cli/catalog/project-catalog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
project-repositories:
- name: "obaas"
description: "RESTful Greeting service for Oracle Backend Microservices and AI"
url: "https://github.com/oracle/spring-cloud-oci/tree/main/spring-cli/projects/obaas"
tags:
- "obaas"
- "java-17"
- "rest"
- "web"
- "boot-3.4.x"
55 changes: 55 additions & 0 deletions spring-cli/projects/obaas/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
== Basic Spring Web Application for Oracle Backend for Spring Boot and Microservices

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`.

It will respond with a JSON representation of a greeting, as the following listing shows:

====
[source,json]
----
{"id":1,"content":"Hello, World!"}
----
====

You can customize the greeting with an optional `name` parameter in the query string, as the following listing shows:

====
[source,text]
----
http://localhost:8080/greeting?name=User
----
====

The `name` parameter value overrides the default value of `World` and is reflected in the response, as the following listing shows:

====
[source,json]
----
{"id":1,"content":"Hello, User!"}
----
====

=== Building and running locally

[source,bash]
----
./mvnw spring-boot:run -Dspring-boot.run.profiles=local
----

Then access the endpoint

[source,bash]
----
curl http://localhost:8080/greeting?name=User
----

== About the sample code

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.
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.

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.

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.

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.
File renamed without changes.
Loading
Loading