forked from fafeidou/fast-cloud-nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
qinfuxiang
committed
Nov 22, 2021
1 parent
4b23521
commit 82ba9cf
Showing
4 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
fast-boot-examples/auto-configure/src/main/java/fast/boot/autoconfigure/bind/BinderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package fast.boot.autoconfigure.bind; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "binder.test") | ||
public class BinderTest { | ||
private String bname; | ||
|
||
private Integer bage; | ||
|
||
private BinderInnerTest binderInnerTest; | ||
|
||
|
||
public String getBname() { | ||
return bname; | ||
} | ||
|
||
public void setBname(String bname) { | ||
this.bname = bname; | ||
} | ||
|
||
public Integer getBage() { | ||
return bage; | ||
} | ||
|
||
public void setBage(Integer bage) { | ||
this.bage = bage; | ||
} | ||
|
||
public BinderInnerTest getBinderInnerTest() { | ||
return binderInnerTest; | ||
} | ||
|
||
public void setBinderInnerTest(BinderInnerTest binderInnerTest) { | ||
this.binderInnerTest = binderInnerTest; | ||
} | ||
|
||
public static class BinderInnerTest{ | ||
|
||
private String innerName; | ||
|
||
private Integer innerage; | ||
|
||
public String getInnerName() { | ||
return innerName; | ||
} | ||
|
||
public void setInnerName(String innerName) { | ||
this.innerName = innerName; | ||
} | ||
|
||
public Integer getInnerage() { | ||
return innerage; | ||
} | ||
|
||
public void setInnerage(Integer innerage) { | ||
this.innerage = innerage; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...mples/auto-configure/src/main/java/fast/boot/autoconfigure/bootstrap/BinderBootstrap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package fast.boot.autoconfigure.bootstrap; | ||
|
||
import fast.boot.autoconfigure.bind.BinderTest; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.context.properties.bind.BindResult; | ||
import org.springframework.boot.context.properties.bind.Bindable; | ||
import org.springframework.boot.context.properties.bind.Binder; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
/** | ||
* @author qinfuxiang | ||
*/ | ||
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(); | ||
} | ||
|
||
} |
10 changes: 9 additions & 1 deletion
10
fast-boot-examples/auto-configure/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
user.name=hello | ||
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 |
10 changes: 10 additions & 0 deletions
10
fast-boot-examples/auto-configure/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
helloWorld: | ||
properties: | ||
spring: | ||
json: | ||
trusted: | ||
packages: '*' | ||
type: | ||
mapping: fast.cloud.nacos.fastbootkafka.domain.TopicATest:fast.cloud.nacos.fastbootkafka.domain.TopicATest | ||
|
||
|