preface

In today’s microservices world, we are likely to generate many applications every day. For spring Boot-based applications, JAR packages are used to start applications, which is simple and efficient and does not need to rely on external TOMCAT. Currently, most microservices are based on Spring Boot applications. Although official shortcuts for automatically generating applications are provided, they are not easy to customize. Based on this, summarize a set of code templates.

Top-level design principles

Pack it up once, run it around. Application packages are completely separated from the specific environment and equipment room, and are configured in a unified manner as far as possible. On this basis, the complexity of services caused by the framework is shielded as far as possible, while maintaining flexibility and intervention.

Introduction to engineering structure

All are standard MAVEN projects

  • Core/Module where the core engineering code resides

  • Client/two library sub-module, store dubbo interface definition, constant code

Engineering graphic

Write custom generated shell scripts

#! /bin/sh if [ "$1" == "" ]; then echo "app name must not be empty\n" echo "usage:" echo "\tsh generate APPNAME" exit fi PKGNAME=`echo $1 | sed "S -//g" 'cp -r /demoserver $1 echo" Now generating new project withe name $1" rm -fr ./$1/core/src/main/resources/special rm -fr ./$1/*.iml rm -fr ./$1/client/*.iml rm -fr ./$1/core/*.iml mv ./$1/client/src/main/java/com/dougwang/demoserver ./$1/client/src/main/java/com/dougwang/$PKGNAME mv ./$1/core/src/main/java/com/dougwang/demoserver ./$1/core/src/main/java/com/dougwang/$PKGNAME find ./$1 -type f -name "*.java" -exec sed -i '' "s/dubbodemoserver/$PKGNAME/g" {} \; find ./$1 -type f -name "*.properties" -exec sed -i '' "s/dubbodemoserver/$1/g" {} \; find ./$1 -type f -name "app.xml" -exec sed -i '' "s/dubbodemoserver/$PKGNAME/g" {} \; find ./$1 -type f -name "pom.xml" -exec sed -i '' "s/dubbodemoserver/$1/g" {} \; find ./$1 -type f -name "assembly.xml" -exec sed -i '' "s/dubbodemoserver/$1/g" {} \; echo "all done!!!"Copy the code

Happy moment

When we need to create a new application, we just do it

Bash Generate studyDemo

Empty applications are generated.

scalability

You can modify the template code to fit your actual business needs

Git address:

Github.com/mikewang88/…

reference

Ke.qq.com/course/8042…

Ke.qq.com/course/4748…