springboot2.x from zero to one (2, plug-in and basic environment development)

1. If you are used to idea, you will feel that Eclipse has a low texture. The beauty and functionality of the webstrom and idea interfaces are really delicious. Let’s first introduce a few plugins that I’m also using, and leave a name for backup

1.1 lombok and swagger plugin

setting — plugins search for lombok, install and restart. The pom file can be used by adding dependencies.

<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
</dependency>
    <!--swagger2-->
<dependency>
      		<groupId>io.springfox</groupId>
      		<artifactId>springfox-swagger2</artifactId>
      		<version>2.6.1</version>
</dependency>
<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.6.1</version>
</dependency>

Annotation development @Data@Builder@AllArgsConstructor@NoArgsConstructor includes methods such as full-parameter construction, no-parameter construction, builder, set, get, tostring, etc., basically covering all the methods that need to be used in the model. Needless to say how to use Baidu.
Insert picture description here
Usage of swagger2 (interface annotation, visualization ui)
Insert picture description here
Insert picture description here

1.2 hibernate-validator parameter verification

These validation rule annotations are defined in the JSR 303 (java) specification, but JSR 303 is only a specification, and there are not many specific implementations. Currently, hibernate-validator is usually used for unified parameter verification, which is an implementation of JSR 303 specification.

<!-- spring-boot-start-web中已集成,在使用其他框架时自己选择是否需要加入--->
<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-validator</artifactId>
   <version>5.2.4.Final</version>
</dependency>

Insert picture description here
Insert picture description here

1.3 Rainbow Brackets Multi-colored curly braces (still a bit useful)

Insert picture description here

1.4 Maven Helper

Open the pom file directly, you can view the number of dependencies, and automatically analyze whether the jar package has conflicts

Insert picture description here

1.5 Jackson for serialization and deserialization

By default, SpringBoot uses Jackson as a class library for JSON data format processing. Jackson is excellent in all aspects and does not need to be packaged.
Deserialization : When the client uploads the requested data to the server, it automatically processes the strings and numbers in the JSON data object and converts them to objects containing Date type, Integer, etc.
Serialization : Convert entity objects into JSON strings according to the specified format and orderInsert picture description here
Insert picture description here

1.6 Free Mybatis Plugin: Jump between mybatis xml id and interface

1.7 Common Utils tools

    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
    </dependency>

Insert picture description here

1.8 Mybatis Log Plugin: Quickly print SQL statements
1.9 Alibaba Java Coding Guidelines: Alibaba Development Guidelines
https://github.com/alibaba/p3c
1.10 RestfulToolkit: Quickly locate the controller layer interface, interface testing
1.11 CodeGlance: vscod right code map

2 Configuration file writing and reading

2.1 Load global configuration

Spring boot will start at the beginning—run()—prepareEnvironment—configureEnvironment—configureProfiles—read from the configuration file completed by load. By default, there is only one global configuration file: application.yml or application.properties
Insert picture description here

2.2 The location of the configuration file determines the read priority — the configuration at the 1 position has the highest priority

Insert picture description here

2.3 Use @ImportResource to load Spring's xml configuration file (can be used to solve the bean object injection in the filter initialization phase)

Add @ImportResource(locations = {"classpath:beans.xml"}) to the spring boot application entry startup class.
In the era when there is no Spring annotation, spring related configuration is done through xml, such as beans.xml. The following XML configuration means: instantiate and inject com.asky.servicesDemo.service.TestBeanService into the Spring context.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="testBeanService" class="com.zimug.bootlaunch.service.TestBeanService"></bean>
</beans>

2.4 SpringBoot integrates Netflix Archaius to achieve configuration management

Archaius Development Guide https://github.com/Netflix/archaius/wiki/Users-Guide
introduces dependency Jar package

   <dependency>
      <groupId>com.netflix.archaius</groupId>
      <artifactId>archaius-core</artifactId>
      <version>0.7.6</version>
    </dependency>

Dynamically read configuration items

private DynamicStringProperty hello = DynamicPropertyFactory.getInstance().getStringProperty("student.age","zhangSan");

Configure config.properties

student.age=18

Dynamic modification of configuration items can be completed without restarting

Guess you like

Origin blog.csdn.net/csfun1/article/details/109635132