WebShop implementation with microservices.
You can do the build and run in one command.
docker-compose up --build --detachWhen you have maven installed on your machine, you can configure the docker-compose build to use existing java executables. These java executables needs to be compiled with maven before you running docker-compose.
You can use the enviroment variable BUILD_FROM to select which dockerfile is used for the build.
If you obmit this variable, then the build from maven sources is used by default.
-
with
BUILD_FROM=MavenSourcesthe source code is compiled during the docker build using themaven:3.6.3-openjdk-11-slimimage. Therefore maven needs to download all dependencies, as it cannot reuse the hosts local repository. This might increase your build time.BUILD_FROM=MavenSources docker-compose build
-
with
BUILD_FROM=ExecutableJarthe pre-compiled jar executable is packed into theopenjdk:11-jre-slimimage. This requires you to compile the sources on the host system before the docker build.mvn clean package -DskipTests BUILD_FROM=ExecutableJar docker-compose build
You also can use the package-build-up.cmd script for compiling the sources with your local maven, building the docker images and start the services.
- The maven pom in your working directory is used for compilation.
- The first argument is passed to maven a artifactId to select the builded project, even if your working directory pom contains other projects.
- The following arguments are passed to
docker-compose upfor starting other services, too. - You can pass the same arguments as for
docker-compose buildanddocker-compose up, to specify a service.
Example usage:
-
Run it in your project folder without arguments, to build and start the whole application:
package-build-up.cmd
-
Pass a service name to build and start this specific service, only. Its dependend services are included automatically by docker.
package-and-up.cmd category-service
-
Pass a second service name to start this service, too. This only rebuild the category service, but starts the whole application.
package-and-up.cmd category-service zuul-server
-
Optionally if you want to predownload used docker images, do a pull first.
docker pull openjdk:11-jre-slim docker pull openjdk:11-slim docker pull maven:3.6.3-openjdk-11-slim
-
Compile the sources
mvn clean package -DskipTests
-
Build the services
BUILD_FROM=ExecutableJar docker-compose build
-
Optionally removes containers, networks and the local MySql data storage volume for a fresh database initialization.
- Pass the
--rmi localto remove local images, from previous executions. - Pass the
--remove-orphansto remove undefined service, from previous developments.
docker-compose down --volumes --rmi local --remove-orphans - Pass the
-
Run the services
docker-compose up --detach
The Webshop API is provided by the Zuul server at http://localhost:8081/webshop-api/.
Open the following links to view:
- WebShop Frontend http://localhost:8080/WebShop-1.0.0/
- API-documentation http://localhost:8082/
- Registered instances at Eureka server http://localhost:8761/
- Hystrix Dashboard at Zuul server http://localhost:8081/hystrix
- Monitor the Webshop API with Hystrix http://localhost:8081/hystrix/monitor?stream=http%3A%2F%2Flocalhost%3A8081%2Fturbine.stream&title=Webshop%20API
The API is modeled with the RESTful API Modeling Language RAML. The file api.raml contains the documentation of the api.
There are two ways to generate the API-Documentation
- Docker
- Start
docker-compose up api-docs - Open (http://localhost:8080) to view the documentation
- Start
- raml2html
cd documentation- (first time)
npm install npm run buildornpm run build:watchto automatically build on changes- open the generated file
api-docs.html
For local development you should have
- the JDK 11
- and Apache Maven 3.6.3 installed.
Also check if your JAVA_HOME environment variable is configured correctly.
You can generate an initial Spring Boot Core project using Spring Initializr.
- Open the pre-configured example and define your customization.
Follow the Guides to create some inital code.
To run your application locally, goto to your working directory containing the pom.xml and:
-
Start the database.
docker-compose up --detach db
-
Start the application using
mvn spring-boot:run
-
Check the console output, to see on which port Tomcat has started.
-
Open localhost on this port
http://localhost:$PORT/greeting?name=Userand check for a response.
Body-Parameter für Token:
grant_type: password username: admin password: password scope: message.read
Spring Data JPA implement filtering with optional parameters:
- Spring @RequestParam Annotation
- Spring Data JPA Query by Example
- Spring Data Repositories Query Methods
Creating the composite service and call core services:
- Spring 5 WebClient
- Spring WebClient – GET, PUT, POST, DELETE examples
- deprecated for our used Spring version (5.2.10 / 5.3.1)
Eureka-Ribbon Discovery:
Microservice Security mit OAuth2:
- Spring Security OAuth2 Boot
- Microservices Security with OAuth2
- Advanced Microservices Security with Spring and OAuth2
- OAuth2 configure Authorization and Resource server
- Method Security Common Built-In Expressions (@PreAuthorize)
- OAuth2
More development related articles:
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Spring Web
- Spring Boot DevTools
- Spring Boot Actuator
- Spring Data JPA
- OAuth2 Client
- Spring Cloud Netflix Eureka
The following guides illustrate how to use some features concretely: