Spring Boot Document Learning Note DAY01

Source: Internet
Author: User

1. the role of using spring-boot-starter-parent in Pom.xml:

Maven users can inherit from the Spring-boot-starter-parent project to obtain sensible defaults. The parent project provides the following features:

    • Java 1.8 As the default compiler level.
    • UTF-8 source encoding.
    • A Dependency Management section, inherited from the Spring-boot-dependencies Pom, that manages the versions of common Depe Ndencies. This dependency management lets your omit <version> tags for those dependencies when used in your own pom.
    • Sensible resource filtering.
    • Sensible plugin configuration (exec plugin, Git commit ID, and shade).
    • Sensible resource filtering for application.properties and application.yml including files (for Profile-specific, Application-dev.properties and Application-dev.yml)

2.pom.xml what configuration, too much, url:

Https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-dependencies/pom.xml

3. the location of the startup class is best in the outermost package:

We generally recommend that's locate your main application class in a root package above other classes. The @EnableAutoConfiguration annotation is often placed on your main class, and it implicitly defines a base "search Packa GE "for certain items. For example, if-writing a JPA application, the package of the @EnableAutoConfiguration annotated class was used to Search for @Entity items.

Using A root package also lets the @ComponentScan annotation is used without needing to specify a Basepackage attribute. You can also use the @SpringBootApplication annotation if your main class was in the root package.

The following listing shows a typical layout:

Com

+-Example

+-MyApplication

+-Application.java

|

+-Customer

| +-Customer.java

| +-Customercontroller.java

| +-Customerservice.java

| +-Customerrepository.java

|

+-Order

+-Order.java

+-Ordercontroller.java

+-Orderservice.java

+-Orderrepository.java


4. use Java configuration as much as possible to avoid using XML configuration

You need don't put all your into @Configuration asingle class. The @Import annotation can used to import additional configuration classes. Alternatively, you can use @ComponentScan the automatically pick up all Spring components, including @Configuration classes.

If you absolutely must use the XML based configuration, we recommendthat you still start with a @Configuration class. You can then Usean @ImportResource annotation to load XML configuration files.

5. Automatic configuration

You need to opt-in to auto-configuration byadding the @EnableAutoConfiguration or @SpringBootApplication annotations @Configuration to one of your classes., add only to a single

6. exclude classes that do not require automatic configuration

@EnableAutoConfiguration (Exclude={datasourceautoconfiguration.class})

Or

You can also control the list of auto-configuration classes to exclude by using the property spring.autoconfigure.exclude .

7.Bean Injection Container

IF you structure your code as suggested above (locating your application class-a root package), you can add @ComponentScan witho UT any arguments. All of your application components ( @Component , @Service , @Repository , @Controller etc.) is automatically registered as Spring Beans.

8. @SpringBootApplication instead of a few notes commonly used

The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ Componentscan with their default attributes

9. Development tools

The Spring-boot-devtools module can be included in any project to provide additional development-time features.

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<optional>true</optional>

</dependency>

</dependencies>

Support code modification after reload startup, if not required:

If you don't want to use the restart feature, you can disable it by using the Spring.devtools.restart.enabled property. In most cases, you can set this property in your application.properties (doing so still initializes the restart Classloade R, but it does isn't watch for file changes).

If you need to completely disable restart support (for example, because it does don't work with a specific library), you nee D to set the Spring.devtools.restart.enabled System property to False before calling Springapplication.run (...), as shown I n the following example:

public static void Main (string[] args) {

System.setproperty ("spring.devtools.restart.enabled", "false");

Springapplication.run (Myapp.class, args);

}

In the process of frequent changes but do not want to start, application.properties inside set the specified file changes to restart:

#重启的文件resouces文件夹中新建文件restart. Trigger and set

Spring.devtools.restart.trigger-file=restart.trigger

This will only restart if the Restart.trigger file is changed

Spring Boot Document Learning Note DAY01

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.