ObjectiveSpringboot for us to do automatic configuration, is indeed convenient and fast, but for beginners, if not understand springboot internal starting principle, will inevitably suffer. So this time the blogger will be with you step by step to uncover the mystery of springboot, let it not mysterious.BodyIf we develop any spring boot project, we will use the following startup class@SpringBootApplication Public class Application { publicstaticvo
This article was reproduced from: https://www.cnblogs.com/shamo89/p/8184960.htmlObjectiveSpringboot for us to do automatic configuration, is indeed convenient and fast, but for beginners, if not understand springboot internal starting principle, will inevitably suffer. So this time the blogger will be with you step by step to uncover the mystery of springboot, let it not mysterious.BodyIf we develop any spring boot project, we will use the following startup class@
1.Spring Boot
Project Download Address: https://download.csdn.net/download/weixin_39549656/10287664 1.1 What is spring Boot
advantages and disadvantages of 1.2.Spring boot
1.3. Quick Start 1.3.1. Setting the parent of Spring boot
Description: The spring boot project must have the parent set to spring Boot's parent, which contains a large number of default configurations, which greatly simplifies our development. 1.3.2. Importing spring boot Web support
1.3.3. Adding a spring boot plugin
This section contains a brief introduction to:1. Spring boot configuration file, using @springbootapplication annotations2. Spring Boot modify Java version and project code3. A standard spring boot code structure4. View the current project automatically configured those modules5. Disable automatic configuration6. Customizing banner and closing bannerOne, Spring boot configuration file, using @springbootapplication
@servise, @Repository, @Conponent, @Controller under the package name and registers as beans.@Bean: Annotations on a method, the current method of life returns a value of one Bean.Global configurations (such as database-related configurations, MVC-related configurations) Use Java configuration, and business bean configurations use annotation configurations (@Servise, @Repository, @Conponent, @Controller).1. @SpringBootApplication@
added jar dependency. Since Tomcat and spring MVC are added to Spring-boot-starter-web, auto-configuration assumes that you are developing a web application and setting Spring accordingly. Starter POMs and Auto-Configuration: the purpose of designing auto-configuration is to better use "Starter POMs", but these two concepts are not directly linked. You can freely select jar dependencies other than starter POMs, and Spring Boot will still do its best to automatically configure your application.
.
springboothelloworldapplicationtests: A basic integration Test class.
Let's take a look at springboothelloworldapplicationfirst.2.1 Boot Boot Springspringboothelloworldapplication has two functions in the Spring boot application: Configuration and Boot boot. First, this is the main spring configuration class. Although spring boot's automatic configuration eliminates many spring configurations, you also need to make a few configurations to enable automatic configuration. Package Com.cl
Reprinted from: https://www.cnblogs.com/shamo89/p/8184960.html; make some understanding comments and modifications that are appropriate for youObjectiveSpringboot for us to do automatic configuration, is indeed convenient and fast, but for beginners, if not understand springboot internal starting principle, will inevitably suffer. So this time the blogger will be with you step by step to uncover the mystery of springboot, let it not mysterious.BodyIf we develop any spring boot project, we will u
> activation> Properties> maven. Compiler.source>1.8Maven.compiler.source> maven. Compiler.target>1.8Maven.compiler.target> maven. Compiler.compilerversion>1.8maven.compiler.compilerVersion> Properties> Profile>4. Spring Boot HelloWorldA feature:The browser sends a Hello request, the server accepts the request and processes it, responding to the Hello World string;1. Create a maven project; (JAR)2. Import Spring boot-related dependencies Parent> groupId>Org.springframework.boo
Springboot startSpringApplication.run(MyBootApplication.class);Springapplication.run start the Springboot application, the main process
To create a spring container object
Create a Bean Component object from the Mybootapplication annotation markup feature into the Spring container (@SpringBootApplication)
In the case of a Web program, the Tomcat server is automatically started and the program is published to the server
Users can a
a string and return it directly to the caller.
Note: @RestController and @RequestMapping annotations are spring MVC annotations (they are not a specific part of spring boot)
@EnableAutoConfiguration annotations
The second class-level annotation is @EnableAutoConfiguration. This note tells spring boot to guess how you want to configure spring based on the added jar dependency. Because Spring-boot-starter-web adds Tomcat and spring MVC, Auto-configuration will assume that you are developing a
class to open the Service governance server implementation,
@EnableEurekaServer
@SpringBootApplication Public
class Springbootapplication {public
static void main (String[] args) {
springapplication.run (springbootapplication.class, args);
}
}
2, by default, the service registry will also try to register itself as a client, so we need to disable its client registration behavior, only need to add the fol
frameworks and does not need to be built on your own. It is easy to configure and get started!
SpringBoot startup annotation @ SpringBootApplication
@ SpringBootApplication is equivalent to @ Configuration, @ EnableAutoConfiguration, and @ ComponentScan are composed of three annotations.
@ Configuration: Indicates that this class is a configuration class.
@ EnableAutoConfiguration: The SpringBoot synta
conclusions:Problems caused by automatic component scanningBy default, we use @SpringBootApplication annotations to automatically get configuration information for an app, but this also brings some side effects to your app. With this annotation, automatic configuration (auto-configuration) and component scanning (component scanning) are triggered, with the use of @Configuration, @EnableAutoConfiguration, and @ Componentscan three annotations work the
conclusions:Problems caused by automatic component scanningBy default, We use @SpringBootApplication annotations to get the App's configuration information automatically, But this also brings some side effects to your app. With this annotation, automatic configuration (auto-configuration) and component scanning (component Scanning) are triggered, with the use of @Configuration, @EnableAutoConfiguration, and @ Componentscan three annotations work the
Specify the memory to runJava-xms10m-xmx200m-jar Xxx.jarSpring boot is packaged into a war package:Let the Springbootapplication class inherit Springbootservletinitializer and rewrite the Configure method, as follows: @SpringBootApplication public class Springbootapplication extends Springbootservletinitializer {@Override protecte D Springapplicationbui
quickly build a spring boot project.
The following directory structure is automatically generated for us through spring INITIALLIZR:|-demo? |-src? |-main? |-java? |-com.example.demo? |-demoapplication.java//Startup class? |-resources? |-static//Placing static resources? |-templates//Front-end templates? |-application.properties//config file? |-test? |-java? |-com.example.demo? |-demoapplicationtests.java//Test startup class? |-target//program will be here after packing?
4. Spring Boot
@SpringBootApplication:Contains @configuration, @EnableAutoConfiguration, @ComponentScan are usually used on the main class.Many springboot developers always use @configuration, @EnableAutoConfiguration and @ComponentScan annotate their main class. Since these annotations are used so frequently, Springboot offers a convenient @springbootapplication option. The @springbootapplication annotation is equivalent
I. List of annotations (annotations)@SpringBootApplication: Contains @componentscan, @Configuration, and @enableautoconfiguration annotations. Where @componentscan let spring boot scan to the configuration class and add it to the program context.@Configuration an XML configuration file that is equivalent to spring and can be checked for type safety using Java code.@EnableAutoConfiguration automatic configuration.@ComponentScan component scans to autom
[Springboot series]--springboot Annotation DaquanI. List of annotations (annotations)@SpringBootApplication: Contains @componentscan, @Configuration, and @enableautoconfiguration annotations. Where @componentscan let spring boot scan to the configuration class and add it to the program context.@Configuration an XML configuration file that is equivalent to spring and can be checked for type safety using Java code.@EnableAutoConfiguration automatic conf
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.