preface

All the time writing code is to write code on the framework written by others, in fact, I always want to build a framework to try, just have the opportunity, I will try to build their own, build good or bad I think it is not important, the important thing is in the process of building the framework, can learn a lot of things. Here I refer to the blog of many great gods on the Internet, mainly referring to the blog of the blogger linked below. The first time to build may be in the overall view and lack of knowledge and experience reserve, if there is any mistake, please immediately correct, the project adopts springboot multi-module structure.

Back-end project address: personal application development framework for SpringBoot2.1

Front-end project address: yWH-vuE-admin

Main reference: Build application development framework based on SpringBoot

Springboot Basic learning: Springboot learning directory

Create the Springboot infrastructure

On the left, select Spring Initializr and the JDK version. I’m using JDK 1.8

Set up groups and artifacts according to your naming conventions, and select Type as Maven POM

Select dependencies that do not select any dependencies to go straight to the next step, until you define the name of the project, and where the project will be stored. Click Finish to complete the creation, remember to select the project storage location, and the final project structure is like this.

The JAR in the tag in the parent POM file must be changed to a POM, otherwise dependencies cannot be passed between modules

<groupId>com.ywh</groupId>
<artifactId>springcloud</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<! The parent pom.xml must be of POM type for passing dependencies between submodules.
<packaging>pom</packaging>
Copy the code

Create Module(submodule)

According to reference blogs and some blogs online. There are many ways to divide modules, most of which are divided into modules according to controller, service, DAO and so on. I think this method is too detailed, and I think this method is suitable for large companies with a large number of people. Each person is responsible for the development of a module, and mistakes can be quickly located. And there is a specific person responsible for revision is ok (may be my cognition is too shallow, understanding wrong).

I can be divided into:

  • Ywh-starter – Core – For your own business code
  • Ywh-starter -cache – Used to store item cache
  • Ywh-starter -security – used for permission authentication
  • Ywh-starter-common – Put some utility classes, as well as some basic constants, variables, enumerated classes, etc

Right-click >New>Module on your project and first create the Core submodule

Creating a Module is also a SpringBoot project, but when selecting a project to save, be sure to create a new file in this project to save our submodules, so that the Module structure does not run outside of us, as shown below

Create yWH-starter -core, YWH-starter -cache, YWH-starter -common, and YWH-starter – Security modules as follows:

Modify the project general configuration

After the project is created, we need to modify all the pm. XML files of the project. First, we need to inherit the parent project in the sub-module PM. XML and delete the spring-boot-starter and spring-boot-starter-test dependencies. XML, the child module will use the parent pom. XML dependency. The child module takes core as an example, and the rest can be modified by core

<! -- Inherit the parent project -->
<parent>
	<groupId>com.ywh</groupId>
	<artifactId>springcloud</artifactId>
	<version>0.0.1 - the SNAPSHOT</version>
	<relativePath>../pom.xml</relativePath> <! -- lookup parent from repository -->
</parent>
Copy the code
<! -- Submodule -->
<modules>
	<module>ywh-starter-cache</module>   <! -- Cache submodule -->
	<module>ywh-starter-common</module>   <! -- Tools module -->
	<module>ywh-starter-core</module>   <! -- Submodule for writing code -->
	<module>ywh-starter-security</module>  <! -- Permissions submodule -->
</modules>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>
Copy the code

Determine the dependencies between modules

Core -> Security ->cache->common ->common ->common ->common -> Common -> Common It is important to avoid circular dependencies (core->security,security->core). For example, modify pom.xml as follows:

<dependency>
    <groupId>com.ywh</groupId>
    <artifactId>security</artifactId>
    <version>0.0.1 - the SNAPSHOT</version>
</dependency>
<! -- Modify the pom.xml of each submodule according to the owning dependency above -->
Copy the code

In the parent pom. XML dependence on the introduction of some of our public respectively as follows, about what depend on the father can be placed in pom. What can be placed under the XML other sub-modules, so I understand, when there are more than two a dependency of sub module USES, will bring up the dependence on the parent pom, this module USES, rely on only this one Can be placed in a separate submodule. Of course, you can put all the dependencies in the parent POM.xml for graphical convenience.

Introduce common dependencies

Introduce some common dependencies in the parent POM file

<! -- Web dependency -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
 
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
 
<! Fastjson dependency package -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.53</version>
</dependency>
 
<! IO stream dependencies have fast read and write, file directory copy and delete, IO operation directory and file listening and other functions -->
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.6</version>
</dependency>
 
<! -- Dependency on file upload and download -->
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.3</version>
</dependency>
 
<! -- provides rich collection operations -->
<dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.2.1</version>
</dependency>
 
<! -- Provides basic encoding and decoding algorithms, such as Base64, MD5, SHA, etc.
<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.11</version>
</dependency>
 
<! -- Rich tool classes like StringUtils -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.8.1</version>
</dependency>
 
<! -- Connection pool -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
    <version>server</version>
</dependency>
Copy the code

Create a YML file and modify the banner chart

Spring Boot uses a global configuration file, application.properties or application.yml, in the SRC /main/resources directory. We can modify some default configuration values in the global configuration file, and change the suffix of all application.properties to.yml. This is not necessary, but you can also change the way of.properties. There are a lot of configurations, but most of them are just default. Specific configuration can be found on the official website, there are a lot of configuration, but most of the default can be used by SpringBoot official configuration file reference

I added configuration files for the development environment (dev) and production environment (PROd) and specified the current environment by setting spring.profiles. Active =dev in application.yml, where yML files must start with application followed by -*.

This site generates a banner for its own project instead of the banner displayed on the console when the SpringBoot project starts. Create banner.txt and put it in the resources root directory. I started the project with Core, so I put it in the submodule of Core.

Modify the startup CoreApplication class, scan with com.yWH, if not added, the configuration class added in other modules will cause scanning failure

@SpringBootApplication(scanBasePackages = "com.ywh")
Copy the code

Integration with Druid + Mybatis-Plus

  • Link: SpringBoot2.1 personal application development framework – integration with Druid + MybatisPlus

Basic controller, Service, front-end package return JSON body, etc

  • Link: personal application development framework for SpringBoot2.1 – implementation of basic controller, service, front-end package return json body, etc

Log customization and global exception handling

  • Link: personal application development framework for SpringBoot2.1 – logging customization and global exception handling

Integrate Redis cache

  • Link: SpringBoot2.1 personal application development framework – integrated Redis cache

Integrated SpringSecurity

  • Link: personal application development framework for SpringBoot2.1 – managing our access rights with SpringSecurity 1
  • Link: personal application development framework for SpringBoot2.1 – managing our access rights with SpringSecurity 2

Integrate VUE to achieve front and rear end separation

  • Link: SpringBoot2.1 personal application development framework – integrated vue for front and back end separation

Package deployment using Docker + Nginx

  • Link: personal application development framework for SpringBoot2.1 – deploy projects using Docker + Nginx

conclusion

This note is finally finished, from the creation of the project to the deployment of the process went through, from 0-1, I know there are many problems; In the building of this framework to solve the past some questions, but there are more new questions, which need to learn to answer, success is not overnight, to slowly; I also want to enrich this framework and modify it into a micro-service architecture for the next stage

  • Springcloud and dubbo
  • Redis advanced
  • System learning for nginx
  • Es Search engine
  • The message queue

Wait, some middleware learning

Back to see my previous chapter notes, in fact is the ink, and the code is not elegant (because of understanding is not enough thorough), what is called grace, in my view is that there is no redundant operation, simple and clear, won’t make a thing is very complicated, it also takes a lot of effort, actually when I write these notes, my idea is, One is to take notes, and then look back, there is a memory, 2 it is to give as I am confused don’t know what to learn provides a train of thought, after all, I the so-called personal framework just put some things together, it feels a bit like the northeast stew, but at the very least, can be as a reference, the use of contents is worth learning.

In my opinion, as a young person, I should constantly enrich my knowledge. Only by learning more, I can think more and have more solutions when doing things.

I like programming, programming gives me a sense of achievement, let me have the motivation to go on learning.