Implementation tutorial of spring boot custom starter
Spring boot uses starter to solve many configuration problems, but how does it solve these problems@ H_ 502_ 1@
Here is a simple example to see how starter sets the default configuration@ H_ 502_ 1@
I Build starter project @ h_ 502_ 1@
@H_ 502_ 1@@H_ 502_ 1@
For a custom starter, the project naming convention is: Custom Name - spring boot- starter@H_502_1 @
Let's take a look at my final directory structure @ H_ 502_ 1@
@H_ 502_ 1@@H_ 502_ 1@
1. Modify POM XML file @ h_ 502_ 1@
In fact, it just added spring boot- autoconfigure@H_502_1 @
I commented out the main method in the app file, and @ h is not used here_ 502_ 1@
2. Receive file @ h corresponding to configuration attribute_ 502_ 1@
3. External Service@H_502_1 @
4. The external service is associated with the corresponding configuration file @ H_ 502_ 1@
5. Starter configuration: spring factories@H_502_1 @
After that, package it into Maven library @ h through MVN clean install_ 502_ 1@
II Spring boot project uses @ h_ 502_ 1@
Create a new spring boot project and select web@ H_ 502_ 1@
Directory structure: @ h_ 502_ 1@
@H_ 502_ 1@@H_ 502_ 1@
Let's take a look at the reference POM xml@H_502_1 @
Take another look HelloController@H_502_1 @
The helloservice here is the one in the custom starter@ H_ 502_ 1@
1. Result: if it is not configured, it should output Hello world@H_502_1 @
@H_ 502_ 1@@H_ 502_ 1@
2. In the configuration file, add hello msg= hahahahahah@H_502_1 @
@H_ 502_ 1@@H_ 502_ 1@
@H_ 502_ 1@@H_ 502_ 1@
This example is very simple. It just shows the main process. The rest is the logical judgment of each plug-in@ H_ 502_ 1@
Reference: @ h_ 502_ 1@
Spring boot actual combat @ h, the subverter of Java EE development_ 502_ 1@
The above tutorial on the implementation of spring boot custom starter is all that Xiaobian has shared with you. I hope it can give you a reference and support more programming tips@ H_ 502_ 1@