本文整理汇总了Java中org.springframework.core.env.MapPropertySource类的典型用法代码示例。如果您正苦于以下问题:Java MapPropertySource类的具体用法?Java MapPropertySource怎么用?Java MapPropertySource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MapPropertySource类属于org.springframework.core.env包,在下文中一共展示了MapPropertySource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDefaultProperty
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
private void addDefaultProperty(ConfigurableEnvironment environment, String name,
String value) {
MutablePropertySources sources = environment.getPropertySources();
Map<String, Object> map = null;
if (sources.contains("defaultProperties")) {
PropertySource<?> source = sources.get("defaultProperties");
if (source instanceof MapPropertySource) {
map = ((MapPropertySource) source).getSource();
}
} else {
map = new LinkedHashMap<>();
sources.addLast(new MapPropertySource("defaultProperties", map));
}
if (map != null) {
map.put(name, value);
}
}
示例2: translateZuulRoutes
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void translateZuulRoutes(ConfigurableEnvironment environment) {
//TODO should be fixed to multiple propertySource usage
MapPropertySource zuulSource = findZuulPropertySource(environment);
if (zuulSource == null) {
return;
}
Map<String, String> customServiceVersions = new HashMap<>();
for (String name : zuulSource.getPropertyNames()) {
extractServiceVersion(zuulSource, name, customServiceVersions);
}
Map<String, Object> properties = new HashMap<>();
properties.put(CUSTOM_SERVICE_VERSIONS_PROP, customServiceVersions);
MapPropertySource target = new MapPropertySource(ZUUL_PROPERTY_SOURCE_NAME, properties);
environment.getPropertySources().addFirst(target);
}
开发者ID:gorelikov,项目名称:spring-cloud-discovery-version-filter,代码行数:20,代码来源:PropertyTranslatorPostProcessor.java
示例3: setUp
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(TarantoolConfiguration.class);
DockerPort dockerPort = docker.containers()
.container("tarantool")
.port(3301);
ImmutableMap<String, Object> env = ImmutableMap.of("tarantoolPort", dockerPort.getExternalPort());
applicationContext.getEnvironment().getPropertySources()
.addFirst(new MapPropertySource("rule", env));
applicationContext.refresh();
TarantoolClientOps bean = (TarantoolClientOps) applicationContext.getBean("tarantoolSyncOps");
String eval = IOUtils.toString(RepositoryIntegrationTests.class.getResource("/init.lua"));
bean.eval(eval);
//
userRepository = applicationContext.getBean(UserRepository.class);
userRepository.deleteAll();
logEntryRepository = applicationContext.getBean(LogEntryRepository.class);
logEntryRepository.deleteAll();
addressRepository = applicationContext.getBean(AddressRepository.class);
addressRepository.deleteAll();
}
示例4: setUp
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
this.applicationContext = new AnnotationConfigApplicationContext();
this.applicationContext.register(TarantoolConfiguration.class);
DockerPort dockerPort = docker.containers().container("tarantool").port(3301);
ImmutableMap<String, Object> env = ImmutableMap.of("tarantoolPort", dockerPort.getExternalPort());
this.applicationContext.getEnvironment().getPropertySources()
.addFirst(new MapPropertySource("rule", env));
this.applicationContext.refresh();
TarantoolClientOps bean = (TarantoolClientOps) applicationContext.getBean("tarantoolSyncOps");
String eval = IOUtils.toString(RepositoryIntegrationTests.class.getResource("/init.lua"));
bean.eval(eval);
userOperations = ((TarantoolOperations<Long, User>) applicationContext.getBean("userTarantoolOperations"));
// userOperations.deleteAll(SPACE_ID);
//
stringUserTarantoolOperations = ((TarantoolOperations<String, User>) applicationContext.getBean("stringUserTarantoolOperations"));
// stringUserTarantoolOperations.deleteAll(SPACE_STRING_ID);
}
示例5: locate
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Override
public PropertySource<?> locate(Environment environment) {
if (!this.enabled) {
return new MapPropertySource(PROPERTY_SOURCE_NAME, Collections.emptyMap());
}
Map<String, Object> config;
try {
GoogleConfigEnvironment googleConfigEnvironment = getRemoteEnvironment();
Assert.notNull(googleConfigEnvironment, "Configuration not in expected format.");
config = googleConfigEnvironment.getConfig();
}
catch (Exception e) {
String message = String.format("Error loading configuration for %s/%s_%s", this.projectId,
this.name, this.profile);
throw new RuntimeException(message, e);
}
return new MapPropertySource(PROPERTY_SOURCE_NAME, config);
}
示例6: getAllProperties
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
public static Map<String,String> getAllProperties(AbstractEnvironment env, String prefix){
int prefixLength = prefix.length();
Map<String, Object> map = new TreeMap<>();
for(Iterator it = (env).getPropertySources().iterator(); it.hasNext(); ) {
org.springframework.core.env.PropertySource propertySource = (org.springframework.core.env.PropertySource) it.next();
if (propertySource instanceof MapPropertySource) {
map.putAll(((MapPropertySource) propertySource).getSource());
}
}
Map<String,String> result = new TreeMap<>();
for(String name: map.keySet()){
if(name.startsWith(prefix)){
result.put(name.substring(prefixLength + 1, name.length()), env.getProperty(name));
}
}
return result;
}
示例7: HiveConnectorFactory
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
/**
* Constructor.
*
* @param catalogName connector name. Also the catalog name.
* @param infoConverter hive info converter
* @param connectorContext connector config
*/
HiveConnectorFactory(
final String catalogName,
final HiveConnectorInfoConverter infoConverter,
final ConnectorContext connectorContext
) {
super(catalogName, infoConverter, connectorContext);
final boolean useLocalMetastore = Boolean.parseBoolean(
connectorContext.getConfiguration()
.getOrDefault(HiveConfigConstants.USE_EMBEDDED_METASTORE, "false")
);
final boolean useFastHiveService = useLocalMetastore && Boolean.parseBoolean(
connectorContext.getConfiguration()
.getOrDefault(HiveConfigConstants.USE_FASTHIVE_SERVICE, "false")
);
final Map<String, Object> properties = new HashMap<>();
properties.put("useHiveFastService", useFastHiveService);
properties.put("useEmbeddedClient", useLocalMetastore);
super.addEnvProperties(new MapPropertySource("HIVE_CONNECTOR", properties));
super.registerClazz(HiveConnectorFastServiceConfig.class,
HiveConnectorClientConfig.class, HiveConnectorConfig.class);
super.refresh();
}
示例8: main
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
public static void main(String[] args) {
try (final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
ctx.getEnvironment().getPropertySources().addFirst(new MapPropertySource("mail", ImmutableMap.of(
"mail.enabled", "true",
"mail.address.from", "[email protected]"
)));
ctx.getEnvironment().setActiveProfiles(Constants.AMAZON_DATABASE);
ctx.register(Context.class);
ctx.refresh();
ctx.start();
final MailService bean = ctx.getBean(MailService.class);
bean.sendImmediate(new MailMessageDTO.Builder()
.withFrom("[email protected]")
.withTo("[email protected]")
.withSubject("Test mail from Amazon SES")
.withBody("<html><body><h1>Hello from Amazon</h1>></body></html>"));
}
}
示例9: shouldConfigureSsl
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Test
public void shouldConfigureSsl() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("vault.ssl.key-store", "classpath:certificate.json");
map.put("vault.ssl.trust-store", "classpath:certificate.json");
MapPropertySource propertySource = new MapPropertySource("shouldConfigureSsl",
map);
configurableEnvironment.getPropertySources().addFirst(propertySource);
SslConfiguration sslConfiguration = configuration.sslConfiguration();
assertThat(sslConfiguration.getKeyStore()).isInstanceOf(ClassPathResource.class);
assertThat(sslConfiguration.getKeyStorePassword())
.isEqualTo("key store password");
assertThat(sslConfiguration.getTrustStore())
.isInstanceOf(ClassPathResource.class);
assertThat(sslConfiguration.getTrustStorePassword()).isEqualTo(
"trust store password");
configurableEnvironment.getPropertySources().remove(propertySource.getName());
}
示例10: configurePropertySources
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
/**
* Add, remove or re-order any {@link PropertySource}s in this application's
* environment.
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @see #configureEnvironment(ConfigurableEnvironment, String[])
*/
protected void configurePropertySources(ConfigurableEnvironment environment,
String[] args) {
MutablePropertySources sources = environment.getPropertySources();
if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
sources.addLast(
new MapPropertySource("defaultProperties", this.defaultProperties));
}
if (this.addCommandLineProperties && args.length > 0) {
String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME;
if (sources.contains(name)) {
PropertySource<?> source = sources.get(name);
CompositePropertySource composite = new CompositePropertySource(name);
composite.addPropertySource(new SimpleCommandLinePropertySource(
name + "-" + args.hashCode(), args));
composite.addPropertySource(source);
sources.replace(name, composite);
}
else {
sources.addFirst(new SimpleCommandLinePropertySource(args));
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:30,代码来源:SpringApplication.java
示例11: onApplicationEvent
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
ConfigurableEnvironment environment = event.getEnvironment();
String url = cleanRemoteUrl(environment.getProperty(NON_OPTION_ARGS));
Assert.state(StringUtils.hasLength(url), "No remote URL specified");
Assert.state(url.indexOf(",") == -1, "Multiple URLs specified");
try {
new URI(url);
}
catch (URISyntaxException ex) {
throw new IllegalStateException("Malformed URL '" + url + "'");
}
Map<String, Object> source = Collections.singletonMap("remoteUrl", (Object) url);
PropertySource<?> propertySource = new MapPropertySource("remoteUrl", source);
environment.getPropertySources().addLast(propertySource);
}
示例12: init
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Before
public void init() {
this.propertySources.addFirst(new PropertySource<String>("static", "foo") {
@Override
public Object getProperty(String name) {
if (name.equals(getSource())) {
return "bar";
}
return null;
}
});
this.propertySources.addFirst(new MapPropertySource("map",
Collections.<String, Object>singletonMap("name", "${foo}")));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:PropertySourcesPropertyValuesTests.java
示例13: testOrderPreserved
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Test
public void testOrderPreserved() {
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
map.put("one", 1);
map.put("two", 2);
map.put("three", 3);
map.put("four", 4);
map.put("five", 5);
this.propertySources.addFirst(new MapPropertySource("ordered", map));
PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(
this.propertySources);
PropertyValue[] values = propertyValues.getPropertyValues();
assertThat(values).hasSize(6);
Collection<String> names = new ArrayList<String>();
for (PropertyValue value : values) {
names.add(value.getName());
}
assertThat(names).containsExactly("one", "two", "three", "four", "five", "name");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:PropertySourcesPropertyValuesTests.java
示例14: loadContext
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Override
public ApplicationContext loadContext(MergedContextConfiguration config)
throws Exception {
SpringApplication application = new SpringApplication();
application.setMainApplicationClass(config.getTestClass());
application.setWebEnvironment(false);
application.setSources(
new LinkedHashSet<Object>(Arrays.asList(config.getClasses())));
ConfigurableEnvironment environment = new StandardEnvironment();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put("spring.jmx.enabled", "false");
properties.putAll(TestPropertySourceUtils
.convertInlinedPropertiesToMap(config.getPropertySourceProperties()));
environment.getPropertySources().addAfter(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
new MapPropertySource("integrationTest", properties));
application.setEnvironment(environment);
return application.run();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:SpringApplicationBindContextLoader.java
示例15: postProcessEnvironment
import org.springframework.core.env.MapPropertySource; //导入依赖的package包/类
@Override
public void postProcessEnvironment(final ConfigurableEnvironment environment, final SpringApplication application) {
if (!"elasticsearch".equalsIgnoreCase(environment.getProperty(PROPERTY_INDEXMANAGER, String.class, "n/a"))) {
return;
}
try {
final URL url = new URL(environment.getRequiredProperty(PROPERTY_HOST));
final String[] userInfo = url.getUserInfo().split(":");
final Map<String, Object> properties = new HashMap<>();
properties.put(PROPERTY_HOST, url.getProtocol() + "://" + url.getHost());
properties.put(PROPERTY_USERNAME, userInfo[0]);
properties.put(PROPERTY_PASSWORD, userInfo[1]);
environment.getPropertySources().addFirst(new MapPropertySource(this.getClass().getName(), properties));
} catch (Exception ex) {
// I just assume there is a foo:[email protected] URL, if not, that's probably ok
}
}