zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    mysql这个垃圾迁移数据费劲半天
    https请求,可设置请求格式
    mybatis plus 使用
    https请求,get post 通用
    根据经纬度,查询最近距离
    redis与mysql一致性
    导入excel
    在idea中git怎么使用
    spring的传播机制
    通过RequestContextHolder获取HttpServletRequest
  • 原文地址:https://www.cnblogs.com/lipengsheng-javaweb/p/11427147.html
Copyright © 2011-2022 走看看