Spring Boot Learning (iv)

Source: Internet
Author: User

@SpringBootApplication

Each Spring boot project has an entry class named *application that has a main method in the entry class . used in the Main method:

Springapplication.run (Demoapplication.class, args);

Start the spring boot app.

Above is the source of @springbootapplication

You can tell that @springbootapplication is a combination of annotations that mainly combine the following annotations

    • @SpringBootConfiguration: This is a configuration note for the Spring Boot project, and it is recommended to use @ springbootconfiguration instead of @configuration in the Spring boot project
    • @EnableAutoConfiguration: Enable automatic configuration, which causes spring boot to automatically configure item configuration items based on the jar packages that are dependent on the project
    • @ComponentScan: The default scan @springbootapplication the class's sibling directory and its subdirectories

To turn off specific automatic configurations

Use @springbootapplication's exclude parameter, for example:@SpringBootApplication (exclude = {Redisautoconfiguration.class})

Starter Pom

Spring boot improves the starter pom to simplify the development of most scenarios, so long as the starter pom required for the application is used, the associated configuration can be dispensed with, and the automatically configured beans provided by spring boot are available

Use XML in special cases

Although spring boot can implement XML-free, there are special cases where you need to use an XML configuration file. You can use @importresource to load the XML configuration file at this time. Example:@ImportResource ({"Classpath:some.xml", "Classpath:other.xml"})

Spring Boot Learning (iv)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.