java.lang.System.clearProperty()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中java.lang.System.clearProperty()方法的一些代码示例,展示了System.clearProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.clearProperty()方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:clearProperty

System.clearProperty介绍

[英]Removes a specific system property.
[中]删除特定的系统属性。

代码示例

代码示例来源:origin: google/guava

@Override
protected void tearDown() throws Exception {
 classReloader.close();
 Thread.currentThread().setContextClassLoader(oldClassLoader);
 System.clearProperty("guava.concurrent.generate_cancellation_cause");
}

代码示例来源:origin: spring-projects/spring-framework

@After
public void cleanup() {
  System.clearProperty(P1);
}

代码示例来源: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 suppressGetenvAccessThroughSystemProperty() {
  System.setProperty("spring.getenv.ignore", "true");
  assertTrue(environment.getSystemEnvironment().isEmpty());
  System.clearProperty("spring.getenv.ignore");
}

代码示例来源: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
@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 resolveSystemProperty() throws Exception {
  System.setProperty("systemProperty", "22");
  Object value = resolver.resolveArgument(paramSystemProperty, null, webRequest, null);
  System.clearProperty("systemProperty");
  assertEquals("22", value);
}

代码示例来源: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 resolveSystemProperty() throws Exception {
  System.setProperty("systemProperty", "22");
  try {
    Mono<Object> mono = this.resolver.resolveArgument(
        this.paramSystemProperty,  new BindingContext(), this.exchange);
    Object value = mono.block();
    assertEquals(22, value);
  }
  finally {
    System.clearProperty("systemProperty");
  }
}

代码示例来源: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

@Before
@After
public void clearProperties() {
  System.clearProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME);
  SpringProperties.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, null);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void trimValuesIsOffByDefault() {
  PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
  System.setProperty("my.name", " myValue  ");
  DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
  bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class)
      .addPropertyValue("name", "${my.name}")
      .getBeanDefinition());
  ppc.postProcessBeanFactory(bf);
  assertThat(bf.getBean(TestBean.class).getName(), equalTo(" myValue  "));
  System.clearProperty("my.name");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
  public void fallbackToSystemProperties() {
    MockServletContext servletContext = new MockServletContext();
    System.setProperty("test.prop", "bar");
    try {
      String resolved = ServletContextPropertyUtils.resolvePlaceholders("${test.prop:foo}", servletContext);
      assertEquals("bar", resolved);
    }
    finally {
      System.clearProperty("test.prop");
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void trimValuesIsApplied() {
  PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
  ppc.setTrimValues(true);
  System.setProperty("my.name", " myValue  ");
  DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
  bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class)
      .addPropertyValue("name", "${my.name}")
      .getBeanDefinition());
  ppc.postProcessBeanFactory(bf);
  assertThat(bf.getBean(TestBean.class).getName(), equalTo("myValue"));
  System.clearProperty("my.name");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void nullValueIsPreserved() {
  PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
  ppc.setNullValue("customNull");
  System.setProperty("my.name", "customNull");
  DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
  bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class)
      .addPropertyValue("name", "${my.name}")
      .getBeanDefinition());
  ppc.postProcessBeanFactory(bf);
  assertThat(bf.getBean(TestBean.class).getName(), nullValue());
  System.clearProperty("my.name");
}

代码示例来源: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");
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void resolveFromLocalProperties() {
  System.clearProperty(P1);
  registerWithGeneratedName(p1BeanDef, bf);
  ppc.postProcessBeanFactory(bf);
  TestBean bean = bf.getBean(TestBean.class);
  assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironment_toFalse() {
  registerWithGeneratedName(p1BeanDef, bf);
  System.clearProperty(P1); // will now fall all the way back to system environment
  ppc.setSearchSystemEnvironment(false);
  ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
  ppc.postProcessBeanFactory(bf);
  TestBean bean = bf.getBean(TestBean.class);
  assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL)); // has to resort to local props
}

相关文章