- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.springframework.beans.factory.config.YamlPropertiesFactoryBean.<init>()
方法的一些代码示例,展示了YamlPropertiesFactoryBean.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlPropertiesFactoryBean.<init>()
方法的具体详情如下:
包路径:org.springframework.beans.factory.config.YamlPropertiesFactoryBean
类名称:YamlPropertiesFactoryBean
方法名:<init>
暂无
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
private Properties loadDiamondData(String dataId, String diamondGroup) {
try {
String data = ConfigService.getConfig(dataId, diamondGroup, 3000L);
if (StringUtils.isEmpty(data)) {
return null;
}
if (dataId.endsWith(".properties")) {
Properties properties = new Properties();
logger.info(String.format("Loading acm data, dataId: '%s', group: '%s'",
dataId, diamondGroup));
properties.load(new StringReader(data));
return properties;
} else if (dataId.endsWith(".yaml") || dataId.endsWith(".yml")) {
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
return yamlFactory.getObject();
}
} catch (Exception e) {
if (e instanceof ConfigException) {
logger.error("DIAMOND-100500:" + dataId + ", " + e.toString(), e);
} else {
logger.error("DIAMOND-100500:" + dataId, e);
}
}
return null;
}
代码示例来源:origin: spring-cloud/spring-cloud-kubernetes
static Function<String, Properties> yamlParserGenerator(
final String[] profiles) {
return s -> {
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
yamlFactory.setDocumentMatchers(properties -> {
String profileProperty = properties.getProperty("spring.profiles");
if (profileProperty != null && profileProperty.length() > 0) {
return asList(profiles).contains(profileProperty) ? FOUND : NOT_FOUND;
}
else {
return ABSTAIN;
}
});
yamlFactory.setResources(new ByteArrayResource(s.getBytes()));
return yamlFactory.getObject();
};
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadArrayOfString() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("foo:\n- bar\n- baz".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo[0]"), equalTo("bar"));
assertThat(properties.getProperty("foo[1]"), equalTo("baz"));
assertThat(properties.get("foo"), is(nullValue()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadArrayOfInteger() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("foo:\n- 1\n- 2".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo[0]"), equalTo("1"));
assertThat(properties.getProperty("foo[1]"), equalTo("2"));
assertThat(properties.get("foo"), is(nullValue()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadResourceWithMultipleDocuments() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource(
"foo: bar\nspam: baz\n---\nfoo: bag".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("baz"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadArrayOfObject() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource(
"foo:\n- bar:\n spam: crap\n- baz\n- one: two\n three: four".getBytes()
));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo[0].bar.spam"), equalTo("crap"));
assertThat(properties.getProperty("foo[1]"), equalTo("baz"));
assertThat(properties.getProperty("foo[2].one"), equalTo("two"));
assertThat(properties.getProperty("foo[2].three"), equalTo("four"));
assertThat(properties.get("foo"), is(nullValue()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadNull() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("foo: bar\nspam:".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bar"));
assertThat(properties.getProperty("spam"), equalTo(""));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadResourceWithSelectedDocuments() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource(
"foo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
factory.setDocumentMatchers(properties -> ("bag".equals(properties.getProperty("foo")) ?
MatchStatus.FOUND : MatchStatus.NOT_FOUND));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("bad"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadResourcesWithOverride() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(
new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes()),
new ByteArrayResource("foo:\n bar: spam".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bar"));
assertThat(properties.getProperty("spam.foo"), equalTo("baz"));
assertThat(properties.getProperty("foo.bar"), equalTo("spam"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadResource() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bar"));
assertThat(properties.getProperty("spam.foo"), equalTo("baz"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadEmptyArrayValue() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("a: alpha\ntest: []".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("a"), equalTo("alpha"));
assertThat(properties.getProperty("test"), equalTo(""));
}
代码示例来源:origin: stackoverflow.com
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
yaml.setResources(new ClassPathResource("default.yml"));
propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
return propertySourcesPlaceholderConfigurer;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadNonExistentResource() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE);
factory.setResources(new ClassPathResource("no-such-file.yml"));
Properties properties = factory.getObject();
assertThat(properties.size(), equalTo(0));
}
代码示例来源:origin: spring-projects/spring-framework
@Test(expected = DuplicateKeyException.class)
public void testLoadResourcesWithInternalOverride() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource(
"foo: bar\nspam:\n foo: baz\nfoo: bucket".getBytes()));
factory.getObject();
}
代码示例来源:origin: spring-projects/spring-framework
@Test(expected = DuplicateKeyException.class)
public void testLoadResourcesWithNestedInternalOverride() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource(
"foo:\n bar: spam\n foo: baz\nbreak: it\nfoo: bucket".getBytes()));
factory.getObject();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadResourceWithDefaultMatchSkippingMissedMatch() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setMatchDefault(true);
factory.setResources(new ByteArrayResource(
"one: two\n---\nfoo: bag\nspam: bad\n---\nfoo: bar\nspam: baz".getBytes()));
factory.setDocumentMatchers(properties -> {
if (!properties.containsKey("foo")) {
return MatchStatus.ABSTAIN;
}
return ("bag".equals(properties.getProperty("foo")) ?
MatchStatus.FOUND : MatchStatus.NOT_FOUND);
});
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("bad"));
assertThat(properties.getProperty("one"), equalTo("two"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadResourceWithDefaultMatch() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setMatchDefault(true);
factory.setResources(new ByteArrayResource(
"one: two\n---\nfoo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
factory.setDocumentMatchers(properties -> {
if (!properties.containsKey("foo")) {
return MatchStatus.ABSTAIN;
}
return ("bag".equals(properties.getProperty("foo")) ?
MatchStatus.FOUND : MatchStatus.NOT_FOUND);
});
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("bad"));
assertThat(properties.getProperty("one"), equalTo("two"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLoadResourceWithoutDefaultMatch() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setMatchDefault(false);
factory.setResources(new ByteArrayResource(
"one: two\n---\nfoo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
factory.setDocumentMatchers(new DocumentMatcher() {
@Override
public MatchStatus matches(Properties properties) {
if (!properties.containsKey("foo")) {
return MatchStatus.ABSTAIN;
}
return ("bag".equals(properties.getProperty("foo")) ?
MatchStatus.FOUND : MatchStatus.NOT_FOUND);
}
});
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("bad"));
assertThat(properties.getProperty("one"), nullValue());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBadResource() {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource(
"foo: bar\ncd\nspam:\n foo: baz".getBytes()));
this.exception.expect(ScannerException.class);
this.exception.expectMessage("line 3, column 1");
factory.getObject();
}
代码示例来源:origin: spring-io/initializr
private static Properties loadProperties(Resource resource) {
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
yamlFactory.setResources(resource);
yamlFactory.afterPropertiesSet();
return yamlFactory.getObject();
}
有没有办法定义命名参数(不是模型属性)来控制 factory.Maybe 的行为? 例如:我想创建一个命名参数,通过可能条件控制RelatedFactory的创建,我尝试这样做: # factorie
我正在阅读有关创 build 计模式的文章,并且设法将自己完全混淆在工厂、抽象工厂和工厂方法之间。 我在下面发布了一个代码片段。是否有人可以告诉我这是哪一个以及(如果可能)可以对代码进行哪些更改以使其
我正在尝试让 Factory Girl 正常工作,但在运行测试时我不断收到此错误: /Users/dm/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1
有两个公共(public)接口(interface): LayoutInflater.Factory和 LayoutInflater.Factory2在 android sdk 中,但官方文档无法说明
在我们针对 rails 3.1.0 应用程序的 rspec 测试中,我们同时使用了 Factory.build 和 Factory.attributes_for。我们发现,如果我们将 Factory.
我想创建一个 ADF v2 管道来调用 Azure SQL 数据库中的存储过程。存储过程有输入参数并会返回多个结果集(大约 3 个)。我们需要把它提取出来。我们正在尝试加载到 4 个不同文件的 Blo
注意:问题位于帖子末尾。 我已经阅读了有关抽象工厂与工厂方法的其他 stackoverflow 线程。我理解每种模式的意图。不过我不太清楚这个定义。 Factory Method defines an
如何将 :subscriber factory 中的“email”属性值传递给它的关联:authentication 例如: factory :subscriber, :class => Subscr
我正在使用 Factory Boy为我的 Django 应用程序创建测试工厂。我遇到问题的模型是一个非常基本的帐户模型,它与 django 用户身份验证模型(使用 django < 1.5)具有 On
假设我们有一个 I/O 绑定(bind)方法(例如进行数据库调用的方法)。此方法既可以同步运行,也可以异步运行。也就是说, 同步: IOMethod() 异步: BeginIOMethod() End
我正在开发基于 Spring Boot Batch XML 的方法。在此示例中,我开发了一个如下所示的 CommonConfig。不知何故,我想对 Spring Batch 使用基于 XML 的方法,
更新 回答如下。万一链接站点消失,您可以使用 mocha stub 初始状态并防止覆盖,如... require 'mocha' class OrderTest "other_state") e
我有一个非常简单的 Rails 4 应用程序,想使用 Factory Girl 编写一些示例测试。该应用程序适用于一些简单的 rspec 测试(全部通过),但是当我将“factory_girl_rai
我们的要求是从 Blob 存储中获取数据并转换为其他表格形式。这可以通过使用 polybase 的 Sql DW 来实现。在这种情况下,Azure 数据工厂的真正作用是什么? 我知道 Azure 数据
如何解决Spring中Bean的自动连接歧义?我们有一个 Dessert 接口(interface),并且有实现该接口(interface)(Dessert)的三种不同的甜点(Bean)。 今天的甜点
我目前正在使用 RSpec 和 Factory_Bot_Rails gem 来测试应用程序,但我遇到了以下问题。 当使用 factory_bot_rails 版本 5.0.2 gem 时,我的工厂现在
我有下面的简化代码,可以异步获取多个承运人的运费,我想知道是否值得转换为使用异步/等待方法,如果是的话,最好的方法是什么?或者如果它现在工作正常,真的不值得付出努力吗?谢谢。 List> lstTas
我是初学者,正在尝试运行第一个简单的代码。 请帮我解决以下问题。 Error on line 11 of document : The element type "session-factory"
我正在寻求使我的 Rails 测试更快。我只有 520 个测试,但它们在 bash 中运行需要 62 秒,在 Rubymine 中运行需要 82 秒。 作为典型 Controller 测试的示例,我使
我们计划使用 IBM Web Experience Factory 来进行 future 的增强。从项目管理的角度来看我们正在考虑使用Maven。但由于没有在线帮助来同时使用这两个东西,我们无法继续前
我是一名优秀的程序员,十分优秀!