An in depth analysis of Spring ES1en starter commonly used dependency modules

  • 2021-01-02 21:50:17
  • OfStack

2 advantages of Spring-boot:

1. The concept of "Convention over Configuration (COC)" based on Spring framework and the road to best practices.

2. Spring-boot-starter automatic configuration dependency modules for everyday enterprise applications, and "out of the box" (spring-ES13en-ES14en-as a naming prefix, all under org.springframenwork.boot package or namespace).

Application log and spring-ES21en-ES22en-ES23en

Common logging system roughly: java util default log support, log4j, log4j2, commons logging, the following spring - boot - starter - logging is also one of them.

maven depends on:


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

springBoot logback will be used as the application log, the framework of application starts, by org. springframework. boot. logging - Logging - Application - Lisetener initialization and use depending on the situation.

If you want to change the application logging Settings provided by springBoot, you can use the following principles:

Follow the conventions of logback and use your own custom logback.xml profile in classpath.

Provide your own ES65en.xml profile anywhere in the file system, then point to the profile via the ES67en.config profile item and reference it, for example in ES69en.properties specify the following configuration:


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

Rapid web application development with spring-ES78en-ES79en-ES80en

maven depends on:


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

Running mvn ES88en-ES89en :run in the current project enables a nested web application directly.

If Cotroller does not provide any service, access to any path will return 1 springBoot default error page (Whitelabel error page).

Embedded Web container level conventions and customizations

By default, es105EN-ES106en-ES107en-ES108en uses nested Tomcat as the Web container to provide HTTP services externally, and the default port 8080 to monitor and provide services externally.

We can also use spring-ES115en-ES116en-ES117en or ES118en-ES119en-ES120en-ES121en as the Web container.

To change the default configuration port, specify in ES125en.properties:


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

Similar configurations include:


server.address
server.ssl.*
server.tomcat.*

If the appeal still does not satisfy the requirements, springBoot supports customization of embedded Web container instances by registering an EmbeddedServletContainerCustomizer-type component in the IoC container


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

Data access with spring-ES142en-ES143en-ES144en

maven depends on:


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

By default, when we do not configure any DataSource,SpringBoot will automatically configure 1 DataSource for us. This automatic configuration method is generally suitable for testing. It is better to configure 1 instance of DataSource for development.

If our project relies on only one database, then 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}

Also automatically configured: JdbcTemplate DateSourceTransactionManager, we just use the injection (@Autowired) is fine

In addition, the database supported by SpringBoot is ES167en-ES168en-ES169en-ES170en ES171en-ES172en-ES173en-ES174en

Application and Application scenarios of spring-ES178en-ES179en-ES180en

AOP:Aspect Oriented Programming, faceted programming

maven depends on:


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

spring-boot-starter-aop Is mainly composed of two parts:

1. Located in spring boot - autoconfigure org. sringframework. boot. autoconfigure. aop. @ Configuration AopAutoConfiguration provide configuration classes and the corresponding configuration items, namely the following 2 items:


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

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

Application security with spring-ES223en-ES224en-ES225en //todo

conclusion


Related articles: