//配置
@Configuration
public class ScheduleServiceConfig{
//定义Bean
@Bean
public RestTemplate restTemplate(){
RestTemplate restTemplate = new RestTemplate ();
return restTemplate;
}
@Bean
@ConfigurationProperties(prefix="email.props")//配置属性
public EmailProps(){
return new EmailProps();
}
}
@Data//lombok添加getter,setter
public class EmailProps{
private String from;
private String cc;
private String bcc;
private String to;
}
application.yml
email:
props:
from: xxx@a.com
cc: a@a.com
bcc: b@a.com
to: c@a.com
@RestController
public class EmailRestEndpoint{
@Autowired
private EmailProps emailProps;
@RequestMapping(value="/test")
public void test(){
log.info("email props={}",emailProps.getFrom());
}
}
网友评论