springboot 读取配置参数

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@PropertySource(value = {"classpath:system.properties"})
@ConfigurationProperties(prefix = "http")
@Component
@Data
public class SystemConfig {

    private String baseUrl;


}
system.properties
  http.baseUrl=http://xxx.com

@Autowired
protected SystemConfig systemConfig;


systemConfig.getBaseUrl()

 

posted @ 2021-10-23 10:36  兜兜转转-一地鸡毛  阅读(135)  评论(0)    收藏  举报