springboot--读取配置文件

config.name=configname
config.password=configpassword
@Configuration
@ConfigurationProperties(prefix = "config")
@PropertySource("classpath:/config.properties")
public class Config {
    private String name;

    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

 @EnableConfigurationProperties({Config.class})  
使用的时候直接注入即可
@Autowired
Config config;

@ComponentScans({@ComponentScan("com.dx.controller"), @ComponentScan("app.config")})

猜你喜欢

转载自www.cnblogs.com/jentary/p/11038564.html