Spring Boot调用application.properties属性值

文件:application.properties

app.name = admin

app.password = 123456

文件:A.java

@Component

@ConfigurationProperties(prefix = "app")

public class YName {

    private String name;

    private String password;

    public String getName() {

        return name;

    }

//......

    public void setPassword(String password) {

        this.password = password;

    }

}

文件:***Controll.java

@Autowired A a;

    @RequestMapping("2")

    public String gety(){

        return a.getName();

    }

你可能感兴趣的:(Spring Boot调用application.properties属性值)