Spring Boot notes and springboot notes
1. if your configuration file is written in the root directory, @ ComponentScan does not require any parameters. All configuration components (@ Component, @ Service, @ Repository, @ Controller, etc) will be automatically registered as Spring Beans.
2. @ SpringBootApplication annotation is equivalent to the use of @ Configuration, @ EnableAutoConfiguration and @ ComponentScan default attributes (you can also customize attributes ):
package com.example.myproject;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScanpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
3. If you want to register listener regardless of the method of application creation, you can add the META-INF/spring. factories file to your project and use the org. springframework. context. ApplicationListerner key.
Example:
org.springframework.context.ApplicationListener=com.example.project.MyListener
4. if you want to run some code after SpringApplication is started, you can implement the ApplicationRunner or CommandLineRunner interface. These two interfaces provide a run method, which will be used in SpringApplication. run (...) called before completion.
5. SpringApplication will read the application. properties attribute file in the following locations.
* The/config subdirectory in the current directory
* Current Directory
*/Config under classpath
* Root directory
6. default location of static content:/static,/public,/resources,/META-INF/resources
7. default location of the template engine file: src/main/resources/templates (templates under the root directory)
8. default error interface: If the interface is a static interface, the file name is the correct error code, such as 404.html, which is stored in the error directory under the static directory. If it is a dynamic page, it is stored in the error directory under the Dynamic Interface directory and the name is error status code.
9. Custom embedded servlet container Configuration:
Network setting: server. port,
Session setting: server. session. persistence
Server. session. timeout
Server. session. cookie .*
If you want to configure it through programming, You can inherit the EmbeddedServletContainerCustomizer Interface
import org.springframework.boot.context.embedded.*;import org.springframework.stereotype.Component;
@Componentpublic class CustomizationBean implements EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { container.setPort(9000); } }