本文整理了Java中java.lang.System.setProperty()
方法的一些代码示例,展示了System.setProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.setProperty()
方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:setProperty
[英]Sets the value of a particular system property.
[中]设置特定系统属性的值。
代码示例来源:origin: spring-projects/spring-framework
@Override
public Class getObjectType() {
System.setProperty("factory.object.type", "true");
return Properties.class;
}
代码示例来源:origin: spring-projects/spring-framework
@Test(expected = IllegalArgumentException.class)
public void defaultProfileWithCircularPlaceholder() {
System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}");
try {
environment.getDefaultProfiles();
}
finally {
System.getProperties().remove(DEFAULT_PROFILES_PROPERTY_NAME);
}
}
代码示例来源:origin: spring-projects/spring-framework
@After
public void after() {
if (enabled != null) {
System.setProperty("ENABLED", enabled);
}
else {
System.clearProperty("ENABLED");
}
if (context != null) {
context.close();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void getActiveProfiles_fromSystemProperties() {
System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, "foo");
assertThat(Arrays.asList(environment.getActiveProfiles()), hasItem("foo"));
System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME);
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setup() {
p1BeanDef = rootBeanDefinition(TestBean.class)
.addPropertyValue("name", "${" + P1 + "}")
.getBeanDefinition();
bf = new DefaultListableBeanFactory();
ppcProperties = new Properties();
ppcProperties.setProperty(P1, P1_LOCAL_PROPS_VAL);
System.setProperty(P1, P1_SYSTEM_PROPS_VAL);
ppc = new PropertyPlaceholderConfigurer();
ppc.setProperties(ppcProperties);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void suppressGetenvAccessThroughSystemProperty() {
System.setProperty("spring.getenv.ignore", "true");
assertTrue(environment.getSystemEnvironment().isEmpty());
System.clearProperty("spring.getenv.ignore");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testReplaceFromSystemPropertyWithDefault() {
System.setProperty("test.prop", "bar");
try {
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop:foo}");
assertEquals("bar", resolved);
}
finally {
System.getProperties().remove("test.prop");
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testReplaceFromSystemPropertyWithExpressionDefault() {
System.setProperty("test.prop", "bar");
try {
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop:#{foo.bar}}");
assertEquals("bar", resolved);
}
finally {
System.getProperties().remove("test.prop");
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void getActiveProfiles_fromSystemProperties_withMulitpleProfiles_withWhitespace() {
System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, " bar , baz "); // notice whitespace
assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("bar", "baz"));
System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("resource")
public void valueFieldsAreProcessedWhenStaticPlaceholderConfigurerIsIntegrated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithValueFieldAndStaticPlaceholderConfigurer.class);
System.setProperty("test.name", "foo");
ctx.refresh();
System.clearProperty("test.name");
TestBean testBean = ctx.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("foo"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void getActiveProfiles_systemPropertiesEmpty() {
assertThat(environment.getActiveProfiles().length, is(0));
System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, "");
assertThat(environment.getActiveProfiles().length, is(0));
System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withResolvablePlaceholder() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithResolvablePlaceholder.class);
System.setProperty("path.to.properties", "org/springframework/context/annotation");
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
System.clearProperty("path.to.properties");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withResolvablePlaceholderAndFactoryBean() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithResolvablePlaceholderAndFactoryBean.class);
System.setProperty("path.to.properties", "org/springframework/context/annotation");
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
System.clearProperty("path.to.properties");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("resource")
public void valueFieldsAreProcessedWhenPlaceholderConfigurerIsSegregated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithValueField.class);
ctx.register(ConfigWithPlaceholderConfigurer.class);
System.setProperty("test.name", "foo");
ctx.refresh();
System.clearProperty("test.name");
TestBean testBean = ctx.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("foo"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resolveDefaultValueFromSystemProperty() throws Exception {
System.setProperty("systemProperty", "bar");
try {
Object result = resolver.resolveArgument(paramSystemProperty, null, webRequest, null);
assertTrue(result instanceof String);
assertEquals("bar", result);
}
finally {
System.clearProperty("systemProperty");
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void reservedDefaultProfile() {
assertThat(environment.getDefaultProfiles(), equalTo(new String[]{RESERVED_DEFAULT_PROFILE_NAME}));
System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "d0");
assertThat(environment.getDefaultProfiles(), equalTo(new String[]{"d0"}));
environment.setDefaultProfiles("d1", "d2");
assertThat(environment.getDefaultProfiles(), equalTo(new String[]{"d1","d2"}));
System.getProperties().remove(DEFAULT_PROFILES_PROPERTY_NAME);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void retrieveMaxCacheSizeFromSystemProperty() {
System.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "42");
assertEquals(42, retrieveMaxCacheSize());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void retrieveMaxCacheSizeFromSystemPropertyContainingWhitespace() {
System.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "42\t");
assertEquals(42, retrieveMaxCacheSize());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resolveDefaultValueSystemProperty() throws Exception {
System.setProperty("systemProperty", "sysbar");
try {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).build();
Object result = resolver.resolveArgument(paramSystemPropertyDefaultValue, message);
assertEquals("sysbar", result);
}
finally {
System.clearProperty("systemProperty");
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resolveNameFromSystemProperty() throws Exception {
System.setProperty("systemProperty", "sysbar");
try {
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader("sysbar", "foo").build();
Object result = resolver.resolveArgument(paramSystemPropertyName, message);
assertEquals("foo", result);
}
finally {
System.clearProperty("systemProperty");
}
}
内容来源于网络,如有侵权,请联系作者删除!