Preface:

The advantage of SpringBoot is that the integration of Java2EE technologies becomes very simple, but it also has its disadvantages, its encapsulation is too strong, if you want to understand the principle of SpringBoot bottom, you must understand SpringMvc, Spring annotations and so on. You can better understand the underlying principles of SpringBoot.

At the same time, it is also a very important technical point in Ali. For a long time, this technical point has also made me toss and turn, thinking about a number of technical points that can be broken. When I was at a loss, one day, I was lucky enough to see this SpringBoot recommended by my friend, which made me feel very excited! In this xiaobian to share with you.

Due to the length of the article, there are answers and analysis at the end of the article

directory

  • Quick start
  • Web development
  • Logs related
  • The data access
  • Scheduled tasks and asynchronous invocation
  • Using messaging middleware
  • Other functions and parsing

The body of the

Quick start

  1. First Spring Boot project
  2. Quick project creation in LntelliJ
  3. Engineering structures for Best Practices (analytic)
  4. Configuration file details

The SpringBoot framework itself does not have specific engineering structure requirements, but following best practices can help us reduce

Few potholes are likely to be encountered, especially with the existence of the Spring package scanning mechanism, which can be avoided if you use a best-practice engineering structure

Less special configuration work.

A typical example

  • Rootpackage structure: com.example.myproject
  • The Application main class application.java is placed under rootPackage, and we usually do some framework configuration sweeps in the Application main class

Tracing configuration, which we put under rootPackage, helps the program reduce manual configuration to load what we want to be loaded by Spring

  • Entity (Entity) and data access layer (Repository) in com. Example. Myproject. Domain under the package
  • Logic layer (Service) in com. Example. Myproject. Under the Service package
  • Web layer (Web) in com. Example. Myproject. Under the Web package
comCopy the code
		+-	exampleCopy the code
				+-	myprojectCopy the code
						+-	Application.javaCopy the code
						|Copy the code
						+-	domainCopy the code
						|		+-	Customer.javaCopy the code
						|		+-	CustomerRepository.javaCopy the code
						|Copy the code
						+-	serviceCopy the code
						|		+-	CustomerService.javaCopy the code
						|Copy the code
						+-	webCopy the code
						|		+-	CustomerController.javaCopy the code
						|Copy the code

See if your current functionality is configured this way. If not, try changing it and see if you can remove some @Configuration.

More analysis:

Web development

  • Develop RESTful interface services and unit tests
  • Develop Web applications using template engines and static resources
  • Unified exception handling for Web applications
  • Automatically build powerful API documentation with Swagger2
  • Extended XML request and response support
  • Use Spring-Security for Security control

Logs related

  • SpringBoot log management
  • Unified handling of Web request logging using AOP
  • Log using Log4j
  • Write logs to MongoDB using Log4j
  • Use Log4j to control different logging levels for different environments
  • Dynamically changing the log level

The data access

Article information is arranged in a document inside, the need for friends can be private letter “frame” to obtain yo

  • Access the database with the JdbcTemplate
  • Use Spring-data-JPA for simple and elegant database access
  • Configuration and use of multiple data sources
  • Access the database using MyBatis
  • Use MyBatis annotation configuration details
  • Cache support (I) annotation configuration and EhCache use
  • Cache support (two) using Redis to do the centralized cache
  • Access to Redis
  • Access to the mongo
  • Add connection pooling to MongoDB
  • Use LDAP to manage user information in a unified manner
  • Transactions are used in SpringBoot
  • Manage database versions using Flyway

spring-boot-starter-mongodb-plus

I created this project on Spring4All’s Github a few weeks ago to extend the official SpringBootStarter

Mongodb support provides more configuration properties, such as connection number configuration.

Let’s see if it’s a lot easier to customize with this extension than before:

How to use

1. In the spring-boot-starter-data-mongodb project, add the following dependencies

Com. Spring4all mongo – plus – spring – the boot – starter 1.0.0. RELEASE

1. Add @enableMongoplus annotation to the main application class, for example:

@EnableMongoPlus

@SpringBootApplication

public class Application {

public static void main(String[]args) {

SpringApplication.run(Application.class,args);

}
}

Available configuration parameters

The following parameters are available

spring.data.mongodb.option.min-connection-per-host=0

spring.data.mongodb.option.max-connection-per-host=100

spring.data.mongodb.option.threads-allowed-to-block-for-connection-multiplier=5

spring.data.mongodb.option.server-selection-timeout=30000

spring.data.mongodb.option.max-wait-time=120000

spring.data.mongodb.option.max-connection-idle-time=0

spring.data.mongodb.option.max-connection-life-time=0

spring.data.mongodb.option.connect-timeout=10000

spring.data.mongodb.option.socket-timeout=0

spring.data.mongodb.option.socket-keep-alive=false

spring.data.mongodb.option.ssl-enabled=false

spring.data.mongodb.option.ssl-invalid-host-name-allowed=false

spring.data.mongodb.option.always-use-m-beans=false

spring.data.mongodb.option.heartbeat-socket-timeout=20000

spring.data.mongodb.option.heartbeat-connect-timeout=20000

spring.data.mongodb.option.min-heartbeat-frequency=500

spring.data.mongodb.option.heartbeat-frequency=10000

spring.data.mongodb.option.local-threshold=15

The preceding values are the default values

Scheduled tasks and asynchronous invocation

  • Scheduled Scheduled Tasks are created
  • Async is used to make asynchronous calls
  • Async Implements asynchronous invocation: custom thread pool
  • Async implements asynchronous calls: graceful closing of thread pools
  • Async implements asynchronous calls: using futures and defining timeouts

Using messaging middleware

Use the RabbitMQ

Other functions and parsing

  • Advantages and disadvantages of automatic configuration and solutions
  • Background configuration
  • Use JavaMailSender to send mail
  • SpringBootActuator monitors endpoints
  • The Info endpoint of the Actuator outputs Git and build information

The last

Pay attention to xiaobian + forward article + private letter 【 frame 】 free access to this PDF information yo!

There is more information on Spring, MyBatis, Netty source code analysis, principles of high concurrency, high performance, distributed, microservice architecture, and JVM performance optimization, all of which are essential knowledge for architects. I believe that for those who have already worked and met technical bottlenecks, there will be content you need here.