提交 48a8f0dc 编写于 作者: 武汉红喜's avatar 武汉红喜

test yml map

上级 897836b3
package org.hongxi.whatsmars.boot.sample.beans;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.Map;
/**
* Created by shenhongxi on 2020/7/17.
*/
@Data
@ConfigurationProperties(prefix = "test")
public class TestProperties {
private Map<String, String> map;
}
......@@ -7,6 +7,7 @@ import org.hongxi.whatsmars.boot.sample.beans.register.PlanetBeanDefinitionRegis
import org.hongxi.whatsmars.boot.sample.beans.register.PlanetBeanDefinitionRegistryPostProcessor2;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
......@@ -20,12 +21,14 @@ import java.util.List;
* Created by shenhongxi on 2020/6/22.
*/
@Configuration
@EnableConfigurationProperties(TestProperties.class)
public class ApplicationConfiguration {
@Order(1)
@ConditionalOnMissingBean
@Bean
public DemoBean demoBean() {
public DemoBean demoBean(TestProperties testProperties) {
System.out.println(testProperties.getMap());
return new DemoBean();
}
......@@ -62,7 +65,7 @@ public class ApplicationConfiguration {
return new PlanetBeanDefinitionRegistryPostProcessor2(parseNames(environment));
}
public List<String> parseNames(Environment environment) {
private List<String> parseNames(Environment environment) {
List<String> names = new ArrayList<>();
String configsKey = "planet.names[%d]";
int configIndex = 0;
......@@ -72,4 +75,5 @@ public class ApplicationConfiguration {
}
return names;
}
}
......@@ -3,4 +3,9 @@ a: xx
planet:
names:
- Mars
- Earth
\ No newline at end of file
- Earth
test:
map:
first: 1
second: 2
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册