When using the Springboot framework for development, we usually add @SpringBootApplication annotations to the main function, and today we will explain @SpringBootApplication, if there are any mistakes, please comment. @SpringBootApplication
@SpringBootApplication source code is as follows:
@Target ({elementtype.type})
Login http://47.92.39.225:8080/See more articles
18. Using @springbootapplication annotations
Many spring boot developers often use @configuration, @EnableAutoConfiguration, @ComponentScan annotate their main class, Since these annotations are used so frequently (especially when following the best practices above), Spring boot provides a handy @springbootapplication annotation instead.
@
The @SpringBootApplication contains three useful annotations, including@SpringBootConfiguration: Look at the source code is actually @configuration, indicating that the current class is a configuration class, like an XML configuration file, and now is a Java configuration file, the effect is the same, generally with @bean.@EnableAutoConfiguration: Enable automatic configuration of the Spring application context to try to guess and configure the beans
Today, we set up the Springboot, and at first encountered a problem, in the helloapplication that I created, @SpringBootApplication could not be introduced by parsing.
Access to the data has been resolved by:Should be caused by Springboot's packet conflict. You need to delete the Spring-boot-autoconfigure folder in the Repository\org\springframework\boot directory, and then in the project MAVEN---Update project
StackOverflow Links:https://stac
To undertake the previous text springboot sentiment edify [email protected] annotation analysis, this article will be based on the above @SpringBootApplication annotation to make a simple analysis
@SpringBootApplicationThis annotation is one of the most concentrated annotations in Springboot and the most widely used annotation. The official also use this note to start the Spring service, we look at the source code@Target(ElementType.TYPE)@Retenti
In spring boot, use @springbootapplication to specify that the class is the application startup class.
Automatically scans for the corresponding annotations under the current class and sub packages register as spring beans,
The application is started in the main method of the class by using the Springapplication Run method.
eg
[Java] view plain copy package Com.lanhuigu; Import org.springframework.boot.SpringApplication; Import org.springframework.bo
1.@SpringBootApplicationIt is a composite annotation, in fact, for springboot applications, the most important thing is that there are only three@Target (Elementtype.type) @Retention (retentionpolicy.runtime) @Documented @inherited//Three of the most important @Configuration @enableautoconfiguration@componentscan public @interface springbootapplication{...}It's too cumbersome to write three annotation at a time@Configuration @enableautoconfiguration@c
Many spring boot developers always use @configuration, @EnableAutoConfiguration and @ComponentScan annotate their main class. Since these annotations are used so frequently (especially if you follow these best practices), Spring boot provides a convenient @springbootapplication choice.@SpringBootApplication annotations are equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with
| + - Service| + - Customerservice.java| + - Web+-Customercontroller.javaWhen using @enableautoconfiguration annotations, you must configure @componentscan (Basepackages = "com.example.web, Com.example.service"), To scan the service and the Webclass, and make a call to theSecond, @SpringBootApplicationWith @springbootapplication annotations, you can solve the problem of too many annotations on the head of
Here's what we often see Springboot startup class Code:
@SpringBootApplication public
class DemoApplication extends Springbootservletinitializer {
@Override
Protected Springapplicationbuilder Configure (Springapplicationbuilder application) {
return application.sources (Demoapplication.class);
} public
static void Main (string[] args) {
springapplication.run (demoapplication.class, args);
}
}
The main focus here is the @
When using the Springboot framework for development, usually we will add @SpringBootApplication annotations on the main function, today for everyone to parse the @SpringBootApplication, if there is an incorrect, welcome criticism. @SpringBootApplication
@SpringBootApplication source code is as follows:
@Target ({elem
@SpringBootApplication is the most important note for spring boot, which is used to configure the startup class quickly.
The previous user was using 3 annotations to annotate their main class. They were @configuration, @EnableAutoConfiguration, @ComponentScan. Since these annotations are generally used together, spring boot provides a unified annotation @springbootapplication.
@
Recently, the company's original framework for the micro-service upgrade, using the Springcould framework, Springboot is the basis of springcloud, with the continuous understanding of springboot, more and more to find it strong, here simply summarize what you learned;
The interesting thing about Springboot is that his startup class, which can be run with a simple main method, removes the annoying XML configuration in spring, it can be packaged directly into a Jar/war package, and the Jar/war pac
Idea New Create Spring Boot Project,
Run main class:springbootjdbcapplication application app exits directly
2018-02-05 10:25:19.795 INFO 93703---[main] o.s.j.e.a.annotationmbeanexporter:registering beans for JMX Exposure on startup2018-02-05 10:25:1
OverviewThis article mainly writes about some common configurations of spring boot.
Spring Boot Basic Configuration Entry class:Spring boot usually has an entry class named *application, and the entry class has a Main method, which is actually a standard Java application entry method. Use Springapplication.run (*application.class, args) in the main method to start the Spring Boot application project.@SpringBootApplication:@
Demand Origin : Someone in the "springboot" public question: Springboot start slow problem when there is a share, thank you. The fans ' question is still to be answered seriously.Let's look at the outline of this section first:(1) Problems caused by automatic component scanning (@SpringBootApplication);(2) How to avoid the problem caused by automatic component scanning (do not use @ springbootapplication);(
;Dependencies>3, write a main program; start the spring boot app/** * @SpringBootApplication to label a main program class, indicating that this is a spring boot application */ @SpringBootApplication Public class helloworldmainapplication { publicstaticvoid main (string[] args) { // Spring apps start up Springapplication.run (helloworldmainapplication. Class, args); }}4, write the relevant controlle
the settings defined in Partent. 2.2 Organization Code
Spring boot does not require any special code structure, however, here are some useful best practices.
Use the "default" package
When a class does not contain a package declaration, it is considered to be under the default package. It is not generally recommended to use default package and should be avoided. Because classes from each jar will be read for spring boot applications that use @componentscan, @EntityScan or @
I. Project creation 1, Idea Creation Springboot Project 1.1, File-->new-->projectNote: Idea needs to select the final version of the community version without the spring Initializ option.SDK Select Java default, URL selection default.1.2. Configuration Name1.3, choose the technology commonly used, because it is a Web project, so here only select the web.1.4. Project explanationThe 1.DemoApplication class is the entry class for the entire project, and this class has a @
,\
Org.springframework.boot.autoconfigure.batch.batchautoconfiguration,\
Org.springframework.boot.autoconfigure.cache.cacheautoconfiguration,\ Org.springframework.boot.autoconfigure.cassandra.cassandraautoconfiguration,\ Org.springframeworK.boot.autoconfigure.cloud.cloudautoconfiguration,\ .....
As you can see, in the Spring.factories file, you define all the classes that may be configured automatically at application run time.
Building Code
Spring boot does not require any special code struct
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.