In-depth analysis of common Spring-boot-starter dependency modules,

Source: Internet
Author: User

In-depth analysis of common Spring-boot-starter dependency modules,

Two major advantages of Spring-boot:

1. The "conventions over configuration (COC)" concept based on the Spring framework and the path to best practices.

2. automatically configure the dependency module for Spring-boot-starter in various daily enterprise application R & D scenarios, and "out-of-the-box" (the spring-boot-starter-is specified as the naming prefix, all of which are located at org. springframenwork. boot package or namespace ).

Application logging and spring-boot-starter-logging

Common log systems include java. util's default log support, log4j, log4j2, and commons logging. The following spring-boot-starter-logging is also one of them.

Maven dependency:

<dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-logging</artifactId>  </dependency>

SpringBoot uses logback as the framework of Application logs. When the program is started, org. springframework. boot. logging-Logging-Application-Lisetener initializes and uses logback as needed.

If you want to change the application log settings provided by springBoot, you can follow the following principles:

Follow the logback conventions and use the custom logback. xml configuration file in classpath.

Provide your own logback at any location in the file system. xml configuration file, and then use logging. the config map points to the configuration file and then references it, for example, in application. properties:

logging.config=/{some.path.you.defined}/any-logfile-name-I-like.log}

Rapid web application development and spring-boot-starter-web

Maven dependency:

<dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-web</artifactId>    </dependency>

Run mvn spring-boot: run in the current project to directly enable a web application nested with tomcat.

If no service is provided for Cotroller, a default springBoot error page (Whitelabel error page) is returned when you access any path ).

Embedded Web Container layer conventions and customization

By default, spring-boot-starter-web uses nested Tomcat as the Web container to provide HTTP services externally. The default port 8080 listens to and provides services externally.

We can also useSpring-boot-starter-jettyOrSpring-boot-starter-undertowAs a Web container.

To change the default port configuration, you can specify the following in application. properties:

server.port = 9000(the port number you want)

Similar configurations include:

server.addressserver.ssl.*server.tomcat.*

If the appeal still fails to meet the requirements, springBoot can customize embedded Web Container instances by registering an EmbeddedServletContainerCustomizer component in the IoC container.

public class UnveilSpringEmbeddedTomcatCustomizer implements EmbeddedServletContainer{    public void customize(ConfigurableEmbeddedServletContainer container){      container.setPort(9999);      container.setContextPath("C\\hello");              ...    }  }

Data access and spring-boot-starter-jdbc

Maven dependency:

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-jdbc</artifactId>  </dependency>

By default, SpringBoot automatically configures a DataSource for us if no DataSource is configured. This automatic configuration method is generally applicable to testing. It is better to configure a DataSource instance by yourself for development.

If our project only depends on one database, it is most convenient to use the parameters provided by the DataSource automatic configuration module:

spring.datasource.url=jdbc:mysql://{datasource host}:3306/{databaseName}spring.datasource.username={database username}spring.datasource.passwd={database passwd}

JdbcTemplate DateSourceTransactionManager will also be automatically configured. We only need to inject (@ Autowired) when using it.

In addition, SpringBoot supports spring-boot-data-jpa spring-boot-data-mongodb databases.

Spring-boot-starter-aop application and application scenarios

AOP: Aspect Oriented Programming, for Aspect-Oriented Programming

Maven dependency:

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-aop</artifactId>  </dependency>

Spring-boot-starter-aop consists of two parts:

1. The @ Configuration class provided by org. sringframework. boot. autoconfigure. aop. AopAutoConfiguration in spring-boot-autoconfigure and the corresponding Configuration items are as follows:

spring.aop.auto=truespring.aop.proxy-target-class=false

2. The spring-boot-starter-aop module provides dependencies for spring-aop aspectjrt and aspectjweaver.

Application security and spring-boot-starter-security // todo

Summary

The above is a commonly used Spring-boot-starter dependency module introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

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.