package top.lileix.sbtest.service; import org.hibernate.validator.constraints.NotBlank; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; /** * Created by lilei on 2017-2-13. */ @Service @ConfigurationProperties( prefix = "t", ignoreUnknownFields = true ) public class TService { @NotBlank private String str; @NotBlank @Value("${t.str}") private String str2; public String getStr2() { return str2; } public void setStr2(String str2) { this.str2 = str2; } public String getStr() { return str; } public void setStr(String str) { this.str = str; } @PostConstruct public void show() { System.out.println(str+"--"+str2); } }
配置文件
t.str=111
两个注解的使用