helloWorld:
properties:
spring:
json:
trusted:
packages: '*'
type:
mapping: fast.cloud.nacos.fastbootkafka.domain.TopicATest:fast.cloud.nacos.fastbootkafka.domain.TopicATest
binder.test.bname=bindname
binder.test.bage=18
binder.test.binderInnerTest.innerName=bindInnername
binder.test.binderInnerTest.innerage=28
binder.test2.list[0]=valuea
binder.test2.list[1]=valueb
binder.test2.list[2]=valuec
binder.test2.list[3]=valued
public class BinderBootstrap {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(EnableHelloWorldBootstrap.class, args);
ConfigurableEnvironment environment = context.getBean(ConfigurableEnvironment.class);
//配置properties 信息
BindResult<Properties> propertiesBindResult = Binder.get(environment)
.bind("hello-world.properties", Properties.class);
BindResult<Map> mapBindResult = Binder.get(environment)
.bind("hello-world.properties", Map.class);
BindResult<BinderTest> binderTestBindResult = Binder.get(environment).bind("binder.test", Bindable.of(BinderTest.class));
BindResult<List<String>> resultList = Binder.get(environment).bind("binder.test2.list", Bindable.listOf(String.class));
System.out.println();
}
}
1、可以看到复杂key value类型,转换为Map和Properties的不同
2、List、复杂类对象都可以获取到值