• spring boot 笔记


    具有组件级别的注解(即生成实例bean被spring容器管理)有:@Component,@Configuration,@Repository,@Service,@Controller,@SpringBootApplication等等,它们都继承了@Component注解。

    只有继承了@Component注解的类才能有@Bean注解
    生成bean的注解@Bean,@Scope,@Primary,@Conditional,@ConditionalOnProperty等等(根据条件来装配bean)

    @import(***.class)注解可以将该类的实例注入到spring容器当中。

    注入注解有@Autowired,@Resource

    @Resource是根据bean的name来装配的,所以一般是@Resource(name="bean的name").
    @Autowired是根据类型来装配的,如果存在多个同种类型的bean,则用@Autowired@Qualifier("bean的name").

    注入也是讲究先后顺序的,只有被注入的对象已经实例化了存在spring上下文档中,才能成功注入。

    查看某些bean是否被注入,用上spring上下文getBean()方法就可以获取。

    辅助注解@ConfigurationProperties
    @Data注解代替setter,getter方法。


    spring boot 有默认的环境变量(鼠标放上去可以点击的),也可以自定义环境变量。有默认实例化好的bean(鼠标放上去可以点击的),也可以自定义bean.

    默认的环境变量有:例如:
    server:
    port: 9999
    spring:
    datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost/springboot?useUnicode=true&characterEncoding=utf8&useSSL=false
    username: root
    password: 123

    默认实例化的bean有: 例如:
    @Autowired
    private Environment env;

  • 相关阅读:
    Collections和Arrays常用方法
    集合(三)------双列集合
    集合(二)------单列集合
    集合(一)----------概述
    泛型
    线程
    Math类和Random类(数学公式相关类)
    时间相关的类
    Runtime类及其常用方法
    第65题:有效数字
  • 原文地址:https://www.cnblogs.com/lipengsheng-javaweb/p/11427147.html
Copyright © 2020-2023  润新知