This is another very cool API for Leo's Music Shop.
For now this API only sells drum kits.
I wanted to learn how Segment SDK in Java behaves in a Spring Boot application.
This is used to validate Segment application onboarding using Java/Spring Boot archetype. I believe it can be used for Groovy and Kotlin as well.
- Spring Web
- Spring Boot
- Spring Security
- Spring Data JDBC
- Spring Data JPA
- Springdoc
- Gradle
- Lombok
- ModelMapper
- JJWT
- Apache Commons Text
This app uses Segment Analytics Java library to track events. The following events are tracked:
- New Customer Registered
- Guest Order Placed
- Order Placed (for registered customers)
You can run this app in your favorite IDE or generate a JAR and run it through the command line.
For any mode, it's necessary to have a JDK installed. This project was written using the JDK 17, but it is code compatible with the JDK 11.
Three settings are required to be set:
jwt.secret
(orJWT_SECRET
environment variable): secret used to generate JWT tokens;spring.profiles.active
(orSPRING_PROFILES_ACTIVE
environment variable): the active spring profile. Used to defined which database to use (seeDatabase
below);segment.write-key
(orSEGMENT_WRITE_KEY
environment variable): The write key from your Segment source.
They are set by default in src/main/resources/application.properties
. You can either modify the file, adding your configuration values, or set the corresponding environment variables.
If you prefer to run the project with an in-memory database, this project has two options:
- SQLite
- H2 (the default)
If you prefer something more permanent, MySQL is supported. Just make sure to have a MySQL instance running. If needed, change the credentials at src/main/resources/persistence-mysql.properties
.
To select which database to use, you can either:
- Modify
src/main/resources/application.properties
file (spring.profiles.active
property) - Start the application with a VM option:
-Dspring.profiles.active=<database>
. - Add an environment variable called
SPRING_PROFILES_ACTIVE
, whose possible values are below.
spring.profiles.active
supports three different values:
sqlite
h2
mysql
If you want to use another database, this project uses JDBC and can be customized for any database that supports JDBC. Feel free to fork it and add the desired support.
This app also requires the write key from your Segment source set. In src/main/resources/application.properties
, change the value of segment.write-key
to the corresponding write key registered in your source.
You can also set an environment variable called SEGMENT_WRITE_KEY
with the value of your Segment source.
This project can be run at the project root, with the command:
./gradlew bootRun
To run through your IDE, follow the corresponding instructions for the Spring Boot in Gradle archetype.
To build the project, use:
./gradlew build
To run the built JAR, use:
java -jar leos-music-shop-api-version-SNAPSHOT.jar
There's a Swagger interface configured at http://localhost:8080/swagger-ui.html