SpringBoot(六) SpringBoot使用汇总(持续更新)

SpringBoot使用汇总(持续更新)

对SpringBoot的使用做一个汇总。

1 ApplicationRunner

启动加载类。在Spring容器启动完成的时候执行。

需要标注@Configuration注解。

@Configuration
public class Test implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println(123);
    }
}

2 Binder

属性绑定。绑定Environment属性。

ApplicationContext context = SpringApplication.run(Application.class, args);
//获取环境
Binder binder = Binder.get(context.getEnvironment());

// 绑定对象
XX xx = binder.bind("a.b", Bindable.of(XX.class)).get();
// 绑定List
List<String> post = binder.bind("a.c", Bindable.listOf(String.class)).get();

// ...,还可以绑定Map等
posted @ 2020-08-04 07:36  造飞机咯  阅读(488)  评论(0编辑  收藏  举报