This project uses Spring Cloud to build a microservice structured Single Page Application.
This project uses several Spring Cloud modules to construct a simple microservice structured web application.
- config-server uses
Spring Cloud Config Server
to manage configurations - eureka-server uses
Spring Cloud Netflix Eureka
to support service registry and discovery - gateway-server uses
Spring Cloud Gateway
to support gateway, authentication and web portal are also included in this module - message-service is a
Spring Boot Application
microservice which registers to eureka-server and requests can be routed from gateway-server
For the front end under gateway-server, it's developed with Vue.js.
moments
├── config-server
│ └── src
│ └── main
│ ├── java
│ └── resources
│ ├── shared // configuration files
│ └── bootstrap.yml
│
├── eureka-server // eureka server for service registry and discovery
│ └── src
│ └── main
│ ├── java
│ └── resources
│ └── bootstrap.yml
│
├── gateway-server
│ └── src
│ └── main
│ ├── java
│ ├── resources
│ │ ├── static
│ │ │ └── dist // webpack bundled resources after npm build
│ │ └── bootstrap.yml
│ └── webapp // front end resources
│ └── src
│ ├── api
│ ├── components // Vue components
│ └── lib
│
├── message-service
│ └── src
│ └── main
│ ├── java
│ └── resources
│ └── bootstrap.yml
│
└── moments-parent // parent maven pom for other modules mainly for dependency management
-
Package the gateway-server front end resources.
$ cd gateway-server $ npm install $ npm run build $ cd .. && mvn clean install
-
Start servers one after another under each module folder:
config-server, eureka-server, message-service, gateway-server
$ cd config-server $ mvn spring-boot:run $ cd eureka-server $ mvn spring-boot:run $ cd message-service $ mvn spring-boot:run $ cd gateway-server $ mvn spring-boot:run
-
Dockerize your microservice
config-server:
$ cd config-server $ docker build . -t configserver --build-arg PACKAGENAME=config-server-0.0.1-SNAPSHOT.jar $ docker run -h config-server -p 8888:8888 -it configserver:latest
-
Gateway:
Log in with user/password or admin/password
-
Message service through gateway
http://localhost:8080/message/get
http://localhost:8080/message/admin/get // Only accessible by admin
Modules beside gateway-server are normal Spring Boot applications, no special configurations are configured for development.
In the gateway-server module, webpack is used to bundle the web resources. In order to develop without frequently re-packaging the web resources and restart Spring Boot application server, this project uses webpack dev server for local development and auto refresh.
Under gateway-server module root, start gateway server:
$ mvn spring-boot:run
Start webpack dev server:
$ npm run start
Access http://localhost:9090.
In this project, websocket is used, Spring Netflix Zuul does not support websocket, so Spring Cloud Gateway is used to support websocket. But Spring Cloud Gateway cannot work well with Spring MVC with warning message Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency
. So Spring Webflux is used.