Two advantages of Spring-boot:
1. The concept of "convention priority over configuration (COC)" based on the Spring framework and the best practice path.
2. For daily enterprise applications, Spring-boot-starter automatically configures the dependency module, and is "out of the box" (conventional spring-boot-starter- as the naming prefix is located in the org.springframenwork.boot package or namespace).
Application logs and spring-boot-starter-logging
Common logging systems include: java.util default log support, log4j, log4j2, commons logging, and the following spring-boot-starter-logging is also one of them.
maven dependencies:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency>
springBoot will use logback as the framework for application logging. When the program starts, it will be initialized and used by org.springframework.boot.logging-Logging-Application-Lisetener according to the situation.
If you want to change the application log settings provided by springBoot, you can follow the following principles:
Follow the logback convention and use your own customized logback.xml configuration file in the classpath.
Provide your own logback.xml configuration file anywhere in the file system, then point to this configuration file through the logging.config configuration item and then reference it, for example, specify the following configuration 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 dependencies:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
Run mvn spring-boot:run in the current project, you can directly enable a web application with tomcat nested.
If there is no Cotroller providing any service, accessing any path will return a springBoot default error page (Whitelabel error page).
Conventions and customization at the embedded web container level
spring-boot-starter-web uses nested Tomcat as a web container to provide HTTP services externally, and the default port 8080 monitors and provides services externally.
We can also use spring-boot-starter-jetty or spring-boot-starter-undertow as web containers.
If you want to change the default configuration port, you can specify it in application.properties:
server.port = 9000(the port number you want)
Similar configurations include:
server.addressserver.ssl.*server.tomcat.*
If the appeal still does not meet the requirements, springBoot supports customization of embedded Web container instances. You can customize embedded Web containers by registering an EmbeddedServletContainerCustomizer type component into the IoC container to customize embedded Web containers by registering an EmbeddedServletContainerCustomizer type component to the IoC container to customize embedded Web containers
public class UnveilSpringEmbeddedTomcatCustomizer implements EmbeddedServletContainer{ public void customize(ConfigurableEmbeddedServletContainer container){ container.setPort(9999); container.setContextPath("C//hello"); ... } }Data access with spring-boot-starter-jdbc
maven dependencies:
<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 a DataSource for us. This automatic configuration method is generally suitable for testing. It is better to develop or configure an instance of DataSource by yourself.
If our project only relies on 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}The automatic configuration is also: JdbcTemplate DateSourceTransactionManager, etc. We just need to inject (@Autowired) when using it.
In addition, SpringBoot also supports databases including spring-boot-data-jpa spring-boot-data-mongodb
Spring-boot-starter-aop application and its usage scenarios
AOP:Aspect Oriented Programming, Oriented Programming
maven dependencies:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency>
spring-boot-starter-aop mainly consists of 2 parts:
1. The @Configuration configuration class and corresponding configuration items provided by org.sringframework.boot.autoconfigure.aop.AopAutoConfiguration located in spring-boot-autoconfigure, namely the following 2 configuration items:
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
Summarize
The above is the commonly used dependency module for Spring-boot-starter introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!