JZTXT
  • 首页
  • Ai
  • Java
  • Python
  • Android
  • Mysql
  • JavaScript
  • Html
  • CSS

SpringBoot不再需要@Autowired来注入属性

发布时间 2023-10-24 10:34:36作者: 海山了-

实操部分

  1. 需要lombok依赖
  2. 在对应需要注入属性的类上添加注解
    @RequiredArgsConstructor
  3. 所有需要注入的属性改为final修饰

为什么

  1. lombok的@RequiredArgsConstructor会生成一个有参(所有的用final修饰的属性)构造器
  2. spring的自动注入会直接根据有参构造器进行注入
    本栏目推荐文章
  • Chrome 浏览器插件 V3 版本 Manifest.json 文件中 Action 的类型(Types)、方法(Methods)和事件(Events)的属性和参数解析
  • 蚂蚁爱购--靠谱的SpringBoot项目
  • 002*:React状态、属性、传值
  • 实时数据流无忧:用 SpringBoot 和 SSE 打造动态前端更新的终极指南
  • Spring属性注入的5种方式
  • 为什么在 Vue 对象上新增一个属性会丢失响应式?
  • springBoot(基础部分)
  • SpringBoot配置报错:Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class
  • 40 个 SpringBoot 常用注解:让生产力爆表!
  • Springboot 全局日期时间格式处理
版权声明:本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。
联系我们