springboot入门填坑

1.注解使用

@Value() 可以引用yml中的属性

我们可以使用下面的注解来读取配置文件中自定义的属性:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

@Configuration
@PropertySource("classpath:configprops.properties")
@ConfigurationProperties(prefix = "mail")
public class ConfigProperties {
public static class Credentials {
private String authMethod;
private String username;
private String password;
// standard getters and setters
}
private String host;
private int port;
private String from;
private Credentials credentials;
private List<String> defaultRecipients;
private Map<String, String> additionalHeaders;

// standard getters and setters
}

可以参考这篇博文