The architecture of Spring Boot is so common that if you don’t master it, sometimes you are embarrassed to say that you are engaged in Java Work. But fire returns to fire, and there are some small problems that we need to pay attention to.
If it is a single project and there are no requirements on startup speed, please ignore it.
Let’s enter the topic below. Under what circumstances will the spring boot project start slower?
The machine hardware configuration for starting the project cannot be delayed, otherwise you will say that the project The startup is slow, and the project still feels that the machine is not good... For example, the network, memory size, number of CPU cores, etc. The requirements are not too high, at least it must be enough.
Put aside all kinds of artificial Factors such as long connection times and slow startup of other components lead to waiting...
Cause 1
One takes 0.1 seconds, 10 takes 1 second, 100 takes 10 seconds...and so on. This is the easiest thing to understand.
Reason 2
No way, usually something that is easy to use and has full functions will always have defects in some places.
As mentioned above, there are many useless configurations. What I want to say here is that spring boot has too many things assembled by itself.
You can see that the spring.factories files are stored in the relevant jar packages of spring boot. When you look inside, you will see that most of them have written a lot of classes, which implement the automatic assembly of spring boot. One of the core.
But if you look carefully, you will find that there are actually many categories that you may not use at all.
But what can you do? Whether you use it or not, at least it will check it for you. Isn’t this a place to spend time?
Reason 3
In a microservice project, it is best to start it within 10 seconds. But most of them can't do it because the projects are not divided into details enough.
Whether it is faster to start one interface, or 10, or more, the answer is obvious. Many projects are large and comprehensive. The so-called large and comprehensive means that there are many functions, complete configurations, various expandable configurations, etc. It may not be comprehensive, but what does this mean? You have many configurations. It doesn’t matter whether they are useful or not. At least there will be a lot more class files that need to be compiled and loaded. You said you want such a project to start quickly, how can it start quickly?
Solution
2. Turn off Spring Boot’s JMX monitoring. Set spring.jmx.enabled=false
3. Set the JVM parameter -noverify, and do not verify the class
4. Delay loading of beans that are not necessarily loaded at startup
5. Use Spring Boot’s global lazy loading
6. Try not to use annotations for AOP aspects, which will cause all methods to be scanned at startup
7. Turn off some endpoint monitoring functions
8. Exclude unnecessary jar dependencies of the project
9. When swagger scans the interface, specify to scan only the classes under a certain path
10. Scan the shrink package of the Feign client interface Scan range
The above is the detailed content of What is the reason why SpringBoot starts slowly?. For more information, please follow other related articles on the PHP Chinese website!