java application文件夹_java 读取 application配置文件

application.ymlhedd:

#单字

younger-brother: 小弟

little-brother: 小兄弟

#类数据

all:

bigSister: 大妹子

littleGirl: 小妹子

#组数据

ofAll:

yourUncle: 你大爷,你三大爷,你二大爷

maven

org.springframework.boot

spring-boot-configuration-processor

true

org.springframework.boot

spring-boot-configuration-processor

true

HeddConfiguration.java/*,

@Configuration:用于定义配置类,可替换xml配置文件,

被注解的类内部包含有一个或多个被@Bean注解的方法,

这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描,并用于构建bean定义,

初始化Spring容器。*/

@Configuration

/*

*读取配置java项目源码 www.fhadmin.org

* */

@ConfigurationProperties("hedd")

public class HeddConfiguration {

private String youngerBrother;

private String littleBrother;

private All all;

public String getYoungerBrother() {

return youngerBrother;

}

public void setYoungerBrother(String youngerBrother) {

this.youngerBrother = youngerBrother;

}

public String getLittleBrother() {

return littleBrother;

}

public void setLittleBrother(String littleBrother) {

this.littleBrother = littleBrother;

}

public All getAll() {

return all;

}

public void setAll(All all) {

this.all = all;

}

}

All.java/**

* @Classname All

* @Description TODO

* @Date 2021/1/16 11:16

* @java项目源码 www.fhadmin.org

*/

public class All {

private String bigSister;

private String littleGirl;

private List ofAll;

public String getBigSister() {

return bigSister;

}

public void setBigSister(String bigSister) {

this.bigSister = bigSister;

}

public String getLittleGirl() {

return littleGirl;

}

public void setLittleGirl(String littleGirl) {

this.littleGirl = littleGirl;

}

public List getOfAll() {

return ofAll;

}

public void setOfAll(List ofAll) {

this.ofAll = ofAll;

}

@Override

public String toString() {

return "All{" +

"bigSister='" + bigSister + '\'' +

", littleGirl='" + littleGirl + '\'' +

", ofAll=" + ofAll +

'}';

}

}

HeddService.java@Slf4j //日志

/*

*@Component

*

*把普通pojo实例化到spring容器中,相当于配置文件中的

*

)

*

泛指各种组件,就是说当我们的类不属于各种归类的时候(不属于@Controller、@Services等的时候),我们就可以使用@Component来标注这个类。

*java项目源码 www.fhadmin.org

* */

@Component

public class HeddService {

/*

* @Autowired 注释,它可以对类成员变量、方法及构造函数进行标注,

*

* 完成自动装配的工作。 通过 @Autowired的使用来消除 set ,get方法。

*

* 在使用@Autowired之前,

*

* */

@Autowired

private HeddConfiguration heddConfiguration;

/*

* @PostConstruct

*

* 该注解被用来修饰一个非静态的void()方法。被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,

*

* 并且只会被服务器执行一次。PostConstruct在构造函数之后执行,init()方法之前执行。

*

*通常我们会是在Spring框架中使用到@PostConstruct注解 该注解的方法在整个Bean初始化中的执行顺序:

*

*Constructor(构造方法) -> @Autowired(依赖注入) -> @PostConstruct(注释的方法)

*

* */

@PostConstruct

public void init() {

log.info("-------------------------------开始--------------------------------------------");

log.info("Get current configuration Single word",heddConfiguration.getYoungerBrother());

log.info("Get current configuration Single word",heddConfiguration.getLittleBrother());

log.info("Get current configuration Class data",heddConfiguration.getAll());

log.info("-------------------------------结束--------------------------------------------");

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值