@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"); }
@Test public void testPropertyPlaceholderConfigurerWithEmptyStringInPlaceholderAsNull() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${ref}").getBeanDefinition()); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); ppc.setNullValue(""); Properties props = new Properties(); props.put("ref", ""); ppc.setProperties(props); ppc.postProcessBeanFactory(factory); TestBean tb = (TestBean) factory.getBean("tb"); assertNull(tb.getName()); }
@Test public void testPropertyPlaceholderConfigurerWithEmptyStringAsNull() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "").getBeanDefinition()); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); ppc.setNullValue(""); ppc.postProcessBeanFactory(factory); TestBean tb = (TestBean) factory.getBean("tb"); assertNull(tb.getName()); }
/** * Gets the property placeholder configurer. * * @return the property placeholder configurer */ @Bean(name = "propertyPlaceholderConfigurer") public static PropertyPlaceholderConfigurer getPropertyPlaceholderConfigurer() { logger.debug("Instantiated propertyPlaceholderConfigurer"); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setLocation(new ClassPathResource("stats.properties")); configurer.setNullValue("NULL"); Properties properties = new Properties(); properties.put("psiprobe.tools.mail.to", "NULL"); properties.put("psiprobe.tools.mail.subjectPrefix", "[PSI Probe]"); configurer.setProperties(properties); configurer.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE"); return configurer; }
@Override public void setNullValue(String nullValue) { this.nullValue = nullValue; super.setNullValue(nullValue); }
@Override public void setNullValue(String nullValue) { super.setNullValue(nullValue); this.nullValue = nullValue; }
@Override public void setNullValue(String nullValue) { this.nullValue = nullValue; super.setNullValue(nullValue); }
@Override public void setNullValue(String nullValue) { this.nullValue = nullValue; super.setNullValue(nullValue); }
@Override public void setNullValue(String nullValue) { super.setNullValue(nullValue); this.nullValue = nullValue; }