Skip to content

ycj28c/SpringBoot-Zoo-Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Springboot Zoo Demo Build Status

A simple demo for springboot & swagger of zoo

Build And Run

Require maven > 3.0.5, java > 1.6

  • Use Maven Build
mvn clean package

run

java -jar target/bootZoo-0.0.1-SNAPSHOT.jar

# if want to run in different port
java -jar -Dserver.port=9999 target/bootZoo-0.0.1-SNAPSHOT.jar

build and run

mvn clean package && java -jar target/bootZoo-0.0.1-SNAPSHOT.jar
  • Use IDE such as eclipse run com/zoo/ZooApplication.java

Deploy In EC2

Want to run springboot in AWS ubuntu node as daemon process, please check 59. Installing Spring Boot applications

  1. create a bootzoodemo.service service
ubuntu~@$ cd /etc/systemd/system
ubuntu~@$ sudo vi bootzoodemo.service
  1. add below content to bootzoodemo.service
[Unit]
Description=bootzoodemo
After=syslog.target

[Service]
User=ubuntu
ExecStart=/opt/bootZoo/bootZoo-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

if run in different port

[Unit]
Description=bootzoodemo
After=syslog.target

[Service]
User=ubuntu
ExecStart=/usr/bin/java -Dserver.port=9999 -jar /opt/bootZoo/bootZoo-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
  1. register service and run in daemon
ubuntu~@$ sudo systemctl enable bootzoodemo.service

#ubuntu~@$ sudo service bootzoodemo start
ubuntu~@$ sudo systemctl start bootzoodemo.service

# check the running status
ubuntu~@$ sudo systemctl status bootzoodemo.service

# stop service
ubuntu~@$ sudo systemctl stop bootzoodemo.service

Access Swagger HTML

http://localhost:8080/swagger-ui.html

or demo here http://54.219.129.91:9999/swagger-ui.html

HTTP Api Example

Follow the "RESTful API Design Guide" in ruanyifeng blog

  • GET /zoos:List all the zoos
  • POST /zoos: Add a new zoo
  • GET /zoos/ID:Get information from target zoo
  • PUT /zoos/ID:Update information for target zoo (must provide all the information)
  • PATCH /zoos/ID:Update information for target zoo (provide parts of information)
  • DELETE /zoos/ID:Delete the target zoo
  • GET /zoos/ID/animals:List all the animals in target zoo
  • DELETE /zoos/ID/animals/ID:Delete the target animal in target zoo