spring boot个人总结笔记

  1. spring boot推荐注解配置,就是在类前加@Configuration
  2. 要是想引用其他配置类,就@Import(xxx.class),比如a是个配置类 b也是配置类,b引用a,写@Import(a.class)在b配置类上
  3. @Bean注解,用于配置类下的方法(目前只会这个),其作用,就是将配置类下的方法一个个都变成了bean组件加入到ioc容器中
  4. ioc容器就是用来管理各个组件的,容器中包含了bean组件即其他们之间的依赖
  5. @Bean它默认是单例模式。我们可以通过修改其scope值来修改它的模式。有什么模式呢?我们只需要知道单例跟多例就好了。其他的,不会
  6. @Bean的id,就是这个注解下面的方法名字。我们可以通过这个id结合@Autowired注解,把配置元数据注入到对应的成员变量中
  7. 配置元数据?也就是我们在@Bean方法下写的return回来的数据
@Configuration
public class HelloConfig {
    
    
   @Bean
   public String hello(){
    
    
       return "hello world!";
   }
}
  • 这个@Bean的id就是hellohello world!是配置元数据
@RestController
public class HelloController {
    
    

    @Autowired
    String hello;

    @GetMapping("/test")
    public String test(){
    
    
        return hello;
    }
}
  • String hello = "hello world!"
  1. @RestController其实是一个web@Controller.会让spring 认为它可以处理输入的web请求
  2. @RequestMapping注解呢,提供了路由信息,它可以告诉任何通过其路径的http请求都应该匹配到该注解下的方法。然后在通过@RestController返回其结果到请求页面上

猜你喜欢

转载自blog.csdn.net/yi742891270/article/details/107722263