My Pandora
Start with a story.
In the past, there was a Java programmer who liked writing programs, studying source code, and reading English documents.But it works in a small company with an old technology stack.
There are many xml configurations in a single system code, configuring the entry adapters for various middleware and similar configurations in different business systems.
Starting a single system is slow.
Dependent web components are started and cannot be deployed quickly.
Public components have complex dependencies, are prone to dependency conflicts, and are out of date.
In the age of springcloud, new great components cannot be quickly integrated.
Moreover, the team uses similar project templates, maven multi-module, which makes it difficult to replace.
Using a unified project template can better standardize the team's code structure, adhere to common component protocols, and reduce the cost of maintaining code for different engineers.
Reality is cruel, I love springboot.
springboot is not new, but the goal of writing on official websites is powerful: build everything;
It can be used correctly and should be refreshing after use.
springboot advocates zero xml and replaces configuration code with java config mode, which may eliminate duplicate configuration.
springboot starts quickly, looks at some source code, and starts some assembly components asynchronously.
springboot is built for fast deployment and has a built-in web container without configuring tomcat.
springboot uses public components in the starter way and resolves dependency conflicts very well.
springboot accumulates a wealth of best practices and provides great support for springcloud and large cloud vendors.
springcloud provides mature supporting micro-service components with more advanced technology and more versatility in the industry.
So how do you find a highway that works best for both new technologies and real-world achievements?
How to open the Pandora box in the picture above to connect reality with dream.
Simple and direct:
Change the project skeleton directly to a springboot-based structure.
Teams are accustomed to multiple modules, so they can be transformed into multiple modules, and the publishing module can be changed to springboot.
The team encapsulated a lot of public components, then used them, added an adapter to transform the springbootstarter core code unchanged, and then used xml to configure it, which is compatible.
The rest is for springboot, various best practices, various useful components, to use, 955 is not a dream, more time to exercise, more time to accompany your family.
It's not a dream to improve your life by expanding your technical influence, allowing more small partners to use it and acting as CTO.
Modify springboot
Alibaba's java programming specifications are prevalent, and three-tier models have long been popular.
Layers correspond to maven's modules, and a simple diagram of the corresponding layers to the modules is drawn.
The original skeleton structure is shown below.
The rest module has the following package conventions:
In accordance with springboot best practices, all classes that require spring Autoscan are placed in the same or lower directory of the xxxApplication class;
dal's package conventions:
Configuring mybatis's generator makes it easy to generate persistent layer code;
I'll post the code too!
Archetype Encapsulation
achetype process:
Before starting the process, check it out Documentation for using maven's archetype .The picture above is a flowchart that I draw after reading the document on the official website.Let's do it step by step.
Required resources are shown in the red box:
1 New Project
Nothing to say, just use maven's quickstart to get out and delete the java code.
Clean up pom.xml and keep only mgav
2 Configure plug-ins for pom
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.springbootpractice.demo</groupId> <artifactId>archetypes-springboot</artifactId> <version>1.0-SNAPSHOT</version> <build> <extensions> <extension> <groupId>org.apache.maven.archetype</groupId> <artifactId>archetype-packaging</artifactId> <version>3.1.1</version> </extension> </extensions> </build> </project>
The main points highlight:
1. Configure extended archetype-packaging;
3 Configure archetype-metadata
<?xml version="1.0" encoding="UTF-8"?> <archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="springboot-multi-module"> <requiredProperties> <requiredProperty key="groupId"> <defaultValue>com.leshiguang.industry.study</defaultValue> </requiredProperty> <requiredProperty key="artifactId"> <defaultValue>demo-services</defaultValue> </requiredProperty> <requiredProperty key="package"> <defaultValue>com.leshiguang.industry.study.demo</defaultValue> </requiredProperty> <requiredProperty key="version"> <defaultValue>1.0-SNAPSHOT</defaultValue> </requiredProperty> <requiredProperty key="projectAuthor"> <defaultValue>fuchun.li</defaultValue> </requiredProperty> </requiredProperties> <fileSets> <fileSet filtered="true" encoding="UTF-8"> <directory/> <includes> <include>pom.xml</include> <include>.gitignore</include> <include>README.MD</include> </includes> </fileSet> </fileSets> <modules> <module id="${rootArtifactId}-api" dir="__rootArtifactId__-api" name="${rootArtifactId}-api"> <fileSets> <fileSet filtered="true" encoding="UTF-8" packaged="true"> <directory>src/main/java</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory/> <includes> <include>pom.xml</include> <include>.gitignore</include> <include>README.MD</include> </includes> </fileSet> </fileSets> </module> <module id="${rootArtifactId}-dal" dir="__rootArtifactId__-dal" name="${rootArtifactId}-dal"> <fileSets> <fileSet filtered="true" encoding="UTF-8" packaged="true"> <directory>src/main/java</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8" packaged="false"> <directory>src/main/resources</directory> <includes> <include>jdbc.properties</include> <include>generateConfig.xml</include> <include>mapper/*.*</include> </includes> <excludes> <exclude>comment.ftl</exclude> </excludes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory></directory> <includes> <include>pom.xml</include> <include>.gitignore</include> <include>README.MD</include> </includes> </fileSet> </fileSets> </module> <module id="${rootArtifactId}-biz" dir="__rootArtifactId__-biz" name="${rootArtifactId}-biz"> <fileSets> <fileSet filtered="true" encoding="UTF-8" packaged="true"> <directory>src/main/java</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8" packaged="false"> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory></directory> <includes> <include>pom.xml</include> <include>.gitignore</include> <include>README.MD</include> </includes> </fileSet> </fileSets> </module> <module id="${rootArtifactId}-rest" dir="__rootArtifactId__-rest" name="${rootArtifactId}-rest"> <fileSets> <fileSet filtered="true" encoding="UTF-8" packaged="true"> <directory>src/main/java</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8" packaged="false"> <directory>src/test/java</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8" packaged="false"> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory></directory> <includes> <include>pom.xml</include> <include>.gitignore</include> <include>README.MD</include> </includes> </fileSet> </fileSets> </module> <module id="${rootArtifactId}-soa" dir="__rootArtifactId__-soa" name="${rootArtifactId}-soa"> <fileSets> <fileSet filtered="true" encoding="UTF-8" packaged="true"> <directory>src/main/java</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8" packaged="false"> <directory>src/test/java</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8" packaged="false"> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory></directory> <includes> <include>pom.xml</include> <include>.gitignore</include> <include>README.MD</include> </includes> </fileSet> </fileSets> </module> </modules> </archetype-descriptor>
xml specification The following:
The basic structure is shown in the following figure, and English is better understood.
Elements inside the node, see link , not difficult.
4 Configure template resources
Here's a description of the variable.
_ rootArtifactId path placeholder_
\({rootArtifactId} file placeholder <br />\){package} package name placeholder
5 Install locally
mvn clean install
6 Local use
Organize into the team, promote this framework, and then continue to organize existing middleware to iterate in this framework.
Open my Pandora early.
Skeleton code point I get!
The original is not easy to reproduce. Please indicate the source.