Chapter 07 Spring-boot creates its own automatic configuration starter pom

Chapter 07 Spring-boot creates its own automatic configuration starter pom

foreword

  • Why use Spring-Boot?

    You can refer to the official documentation.

  • What is Spring-Boot?

    Refer to the official documentation for instructions.

  • official address

    https://spring.io/projects/spring-boot

Target

  • Complete the installation and configuration of Jenkins in Docker.
  • Jenkins installed in Docker can provide external services normally.
  • The Jenkins continuous integration service can be accessed and used normally in the external development environment.

environment

  • **VMware:**VMware Workstation 14 Pro

  • **Linux:**CentOS7.4

  • **Docker:**18.06.0-ce, build 0ffa825

  • **Jenkins:**Jenkins2.121.1

  • **JDK:**jdk1.8.0_172

  • **Spring-Boot:**2.0.4

  • **Eclipse:**Eclipse Neon.3 (4.6.3)

  • spring-tool-suite:

    Version: 3.8.4.RELEASE
    Build Id: 201703310825
    Platform: Eclipse Neon.3 (4.6.3)

  • **Maven:**3.5.0

Goals

Write your own automated configuration and implement the starter pom with a more generic and less coupled configuration.

Implementation

Following the example of http encoding configuration

Realize planning and design

When a certain class exists, the Bean of this class is automatically configured, and the properties of the Bean can be configured in application.properties or application.yml, or one of your own configuration files can be customized.

Implementation steps

1. Create a new starter maven project, just build an ordinary maven project.

2. Modify pom.xml and add configuration

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-autoconfigure</artifactId>
		<version>2.0.3.RELEASE</version>
	</dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-configuration-processor</artifactId>
		<version>2.0.3.RELEASE</version>
		<optional>true</optional>
	</dependency>

3. Attribute configuration, create a new java Bean attribute configuration class, add class annotation configuration:

(1) Properties are configured in the annotation configuration of application.yml or application.properties:

@ConfigurationProperties(prefix = “hello”)

(2) Property configuration is in application.yml or application.properties and deflation is in class annotation configuration of custom property configuration file:

@ConfigurationProperties(prefix=“author”, locations={“classpath:config/author.properties”})

4. Create a new judgment basis class.

Create a Bean of this class according to the existence of this class, which can be a class of a third-party class library.

5. Create a new automatic configuration class and add class annotations.

@Configuration
@EnableConfigurationProperties(DemoHelloProperties.class)

// According to the provided parameters, judge whether the class exists in the class path through the annotation configuration, and automatically configure the Bean when there is no such Bean in the container @ConditionalOnClass(DemoHelloService.class) @ConditionalOnProperty(prefix = “hello

, value = "enabled", matchIfMissing = true)

6. Register configuration. For automatic configuration to take effect, you need to register the automatic configuration class. Create a new META-INF/spring.factories under src/main/resources

Register the newly created automation configuration class in the file, as follows:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=
com.ringyin.demo.autoconfigure.demo.DemoHelloAutoConfiguration

If there are multiple automatic configurations, use "," to separate them. Here, "\" is to read the attributes after the newline.

7. Use the starter. Create a new Spring Boot project and use the custom starter as a dependency.

Start, check the effect, and see if the custom configured starter takes effect.

In the development phase, introduce our custom starter project dependencies. After it is stable, it can be installed to the local library, or the jar can be published to the maven private server.

Eclipse usage skills - open the current directory of the selected file folder or package

Tags: management tools, othersPublished on 2016-08-10 22:25:51

Many times, we need to open the current directory of the selected file (folder, package) in eclipse, and display this directory in the explorer. At this time, we don't want to use "select file/folder/package name – right click – Properties–Location–Copy Path–Open My Computer–Paste Address–Enter ” is a cumbersome way, then you can refer to the following method.

method one:

1. Click Run–External Tools–External Tools Configurations… on the menu bar

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-TIpm9MIQ-1599828415009)(assets/xM4ecT6GJMP8BYXanZzdFxc6nEB6tTWX.png)]

2. Double-click the Program on the left, and fill in the parameters as shown in the figure below

They are:

Name: Open the directory where the current file is located

Location: C:/WINDOWS/explorer.exe

Arguments: ${container_loc}

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-hmuPdAur-1599828415011)(assets/eWD4W4HTERkaTh4nEcQ6fQriDrmadikm.png)]

3. Switch to Common, check External Tools, then click Apply, and then click Close.

images/WX2G5F8EFZ584ry7seQtsSFW76EkTZzT.png

In this way, select the file/folder/package name, and then click the triangle symbol on the right of the following icon to open the directory where the selected file/folder/package name is located in the explorer

Method Two:

3. Switch to Common, check External Tools, then click Apply, and then click Close.

[External link image transfer...(img-7gj4shT5-1599828415015)]

In this way, select the file/folder/package name, and then click the triangle symbol on the right of the following icon to open the directory where the selected file/folder/package name is located in the explorer

Method Two:

Install Eclipse plug-ins, such as: EasyExplorer plug-ins

Guess you like

Origin blog.csdn.net/pointdew/article/details/108541501