-
方式一
-
需使用类上配置@PropertySource(“classpath:test.properties”)
-
增加属性@Value(“${test.username}”)
-
-
方式二:实体类配置文件
- 实体类添加@Component注解
- 使用@PropertySource(“classpath:test.properties”)指定配置文件位置
- 使用@ConfigurationProperties注解设置相关属性
- 使用时通过IOC @Autowired注入
@Component @PropertySource("classpath:test.properties") @ConfigurationProperties(prefix = "test") public class User { }
springboot自定义配置文件映射实体类
最新推荐文章于 2024-05-15 08:56:51 发布