注解:@PropertySource(value = "classpath:application.properties")
配置文件
first.name=张三
first.age=88
first.gander=男
first.birthday=2022.04.12
封装:
package com.mt.pojo;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* @author: 15aaa2
* description:
* date: 2022/1/5 13:37
*/
@Data
@Configuration
@PropertySource(value = "classpath:application.properties")
public class User {
@Value("${first.name}")
private String name;
@Value("${first.age}")
private Integer age;
@Value("${first.gander}")
private String gander;
@Value("${first.birthday}")
private String birthday;
}
使用
@Resource
User user;
@Test
void test1() {
System.out.println(user);
}
测试