SpringBoot文档记录

本文探讨了SpringBoot中如何使用@Import注解导入配置类,以及如何利用@ComponentScan自动发现Spring组件,包括@Configuration类。此外,还介绍了通过@ConfigurationProperties注解从配置文件读取参数值的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpringBoot 在线文档地址

英文版 中文版

15.1 在main函数类中使用@Import注解

You need not put all your @Configuration into a single class. The @Import annotation can be used to import additional configuration classes. Alternatively, you can use @ComponentScan to automatically pick up all Spring components, including @Configuration classes.

释义: 您无需将所有@Configuration放入单个类中。 @Import注释可用于导入其他配置类。或者,您可以使用@ComponentScan自动获取所有Spring组件,包括@Configuration类。

24.56 使用Java类加载 配置文件参数值

配置类

	@ConfigurationProperties("foo")
	public class FooProperties {

	    private final List<MyPojo> list = new ArrayList<>();

	    public List<MyPojo> getList() {
	        return this.list;
	    }

	}	
  • 注: 推荐使用构造函数的方式注入属性值

配置文件

foo:
  list:
    - name: my name
      description: my description
---
spring:
  profiles: dev
foo:
  list:
    - name: my another name
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值