本文整理了Java中java.lang.System.getProperties()
方法的一些代码示例,展示了System.getProperties()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.getProperties()
方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:getProperties
[英]Returns the system properties. Note that this is not a copy, so that changes made to the returned Properties object will be reflected in subsequent calls to getProperty and getProperties.
[中]返回系统属性。请注意,这不是副本,因此对返回的Properties对象所做的更改将反映在对getProperty和getProperties的后续调用中。
代码示例来源:origin: spring-projects/spring-framework
/**
* Remove the system property that points to the web app root directory.
* To be called on shutdown of the web application.
* @param servletContext the servlet context of the web application
* @see #setWebAppRootSystemProperty
*/
public static void removeWebAppRootSystemProperty(ServletContext servletContext) {
Assert.notNull(servletContext, "ServletContext must not be null");
String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);
String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY);
System.getProperties().remove(key);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void afterPropertiesSet() throws Exception {
System.getProperties();
}
}
代码示例来源:origin: spring-projects/spring-framework
public Object makeInstance() {
System.getProperties();
return new Object();
}
}
代码示例来源:origin: spring-projects/spring-framework
public static Object makeStaticInstance() {
System.getProperties();
return new Object();
}
代码示例来源:origin: google/guava
static boolean isAndroid() {
return System.getProperties().getProperty("java.runtime.name").contains("Android");
}
}
代码示例来源:origin: spring-projects/spring-framework
@After
public void tearDown() {
System.getProperties().remove("foo");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testRecursiveFromSystemProperty() {
System.setProperty("test.prop", "foo=${bar}");
System.setProperty("bar", "baz");
try {
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop}");
assertEquals("foo=baz", resolved);
}
finally {
System.getProperties().remove("test.prop");
System.getProperties().remove("bar");
}
}
代码示例来源: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
@Test
public void testSystemPropertyReplacement() {
PropertyEditor editor = new ResourceEditor();
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource resolved = (Resource) editor.getValue();
assertEquals("foo-${bar}", resolved.getFilename());
}
finally {
System.getProperties().remove("test.prop");
}
}
代码示例来源: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
@Test
public void testSystemPropertyReplacement() {
PropertyEditor editor = new ResourceArrayPropertyEditor();
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource[] resources = (Resource[]) editor.getValue();
assertEquals("foo-${bar}", resources[0].getFilename());
}
finally {
System.getProperties().remove("test.prop");
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testReplaceFromSystemProperty() {
System.setProperty("test.prop", "bar");
try {
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop}");
assertEquals("bar", resolved);
}
finally {
System.getProperties().remove("test.prop");
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testReplaceFromSystemPropertyWithExpressionContainingDefault() {
System.setProperty("test.prop", "bar");
try {
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop:Y#{foo.bar}X}");
assertEquals("bar", resolved);
}
finally {
System.getProperties().remove("test.prop");
}
}
代码示例来源: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
public void getActiveProfiles_fromSystemProperties_withMultipleProfiles() {
System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, "foo,bar");
assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("foo", "bar"));
System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME);
}
代码示例来源: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(expected = IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false);
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource resolved = (Resource) editor.getValue();
assertEquals("foo-${bar}", resolved.getFilename());
}
finally {
System.getProperties().remove("test.prop");
}
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!