springboot配置

原创
2017/02/13 18:24
阅读数 129
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

两个注解的使用

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
1 收藏
0
分享
返回顶部
顶部