Spring boot personal summary notes

  1. Spring boot recommends annotation configuration, which is to add before the class@Configuration
  2. If you want to refer to other configuration classes, for @Import(xxx.class)example, a is a configuration class and b is also a configuration class, and b refers to a, which is written @Import(a.class)on the configuration class b
  3. @BeanAnnotation, used for the method under the configuration class (currently only this), its role is to turn all the methods under the configuration class into bean components and add them to the ioc container
  4. The ioc container is used to manage various components. The container contains bean components that are their dependencies.
  5. @BeanIt defaults to singleton mode. We can modify its mode by modifying its scope value. What is the model? We only need to know the single case and multiple cases. Other, no
  6. @BeanThe id is the name of the method under this annotation. We can use this id combined with @Autowired annotation to inject configuration metadata into the corresponding member variable
  7. 配置元数据? That is, the data returned by the return we wrote under the @Bean method
@Configuration
public class HelloConfig {
    
    
   @Bean
   public String hello(){
    
    
       return "hello world!";
   }
}
  • This @Bean of id is hello, hello world!a configuration metadata
@RestController
public class HelloController {
    
    

    @Autowired
    String hello;

    @GetMapping("/test")
    public String test(){
    
    
        return hello;
    }
}
  • String hello = "hello world!"
  1. @RestControllerIt's actually a web @Controller. Let spring think it can handle incoming web requests
  2. @RequestMappingThe annotation provides routing information, which can tell any http request through its path should match the method under the annotation. Then by @RestControllerreturning the result to the request page

Guess you like

Origin blog.csdn.net/yi742891270/article/details/107722263