Refine search
@Bean public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } }
@Test public void multipleLocationsWithDefaultResolvedValue() throws Exception { // SPR-10619 PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer(); ClassPathResource doesNotHave = new ClassPathResource("test.properties", getClass()); ClassPathResource setToTrue = new ClassPathResource("placeholder.properties", getClass()); ppc.setLocations(doesNotHave, setToTrue); ppc.setIgnoreResourceNotFound(true); ppc.setIgnoreUnresolvablePlaceholders(true); DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class) .addPropertyValue("jedi", "${jedi:false}") .getBeanDefinition()); ppc.postProcessBeanFactory(bf); assertThat(bf.getBean(TestBean.class).isJedi(), equalTo(true)); }
@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; }
@Configuration public class SomeClassTestsConfig { @Bean public static PropertySourcesPlaceholderConfigurer properties() throws Exception { final PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Properties properties = new Properties(); properties.setProperty("someProperty", "testValue"); pspc.setProperties(properties); return pspc; } @Bean public SomeClass getSomeClass() { return new SomeClass(); } @Bean public SomeDependency getSomeDependency() { // Mockito used here for mocking dependency return Mockito.mock(SomeDependency.class); } }
@Test public void getAppliedPropertySourcesTooEarly() throws Exception { PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer(); thrown.expect(IllegalStateException.class); ppc.getAppliedPropertySources(); }
@Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); pspc.setLocations(DEV_PROPERTIES); return pspc; } }
@Bean public static PropertySourcesPlaceholderConfigurer propertyConfigurer() { PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); pspc.setIgnoreUnresolvablePlaceholders(true); return pspc; } }
@Bean public static PropertySourcesPlaceholderConfigurer properties(@Qualifier("graviteeProperties") Properties graviteeProperties) { PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer(); propertySourcesPlaceholderConfigurer.setProperties(graviteeProperties); propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true); return propertySourcesPlaceholderConfigurer; }
@Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); yaml.setResources(new ClassPathResource("application.yml")); configurer.setProperties(yaml.getObject()); return configurer; }
@Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setLocations(new Resource[] { new ClassPathResource("db.properties"), new ClassPathResource("app.properties") }); return configurer; }
@Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setLocation(new ClassPathResource("db.properties")); return configurer; }
@Bean(name = "gpSwaggerPropertyConfigurer") @Required public static PropertySourcesPlaceholderConfigurer gpSwaggerPropertyConfigurer( @Value("#{systemProperties['GP_SWAGGER_DATA_DIR']}") String gpConfigDataDir, @Value("#{systemProperties['GP_SWAGGER_FILE_PROP']}") String gpSwaggerFileProp) throws MalformedURLException { PropertySourcesPlaceholderConfigurer gpSwaggerPlaceHolder = new PropertySourcesPlaceholderConfigurer(); gpSwaggerPlaceHolder.setPlaceholderPrefix("gpSwaggerConfigurator{"); gpSwaggerPlaceHolder.setPlaceholderSuffix("}"); gpSwaggerPlaceHolder.setNullValue("@null"); gpSwaggerPlaceHolder.setLocations(swaggerResourcesLoader.loadResources( gpConfigDataDir, gpSwaggerFileProp)); gpSwaggerPlaceHolder.setIgnoreResourceNotFound(Boolean.TRUE); gpSwaggerPlaceHolder.setIgnoreUnresolvablePlaceholders(Boolean.TRUE); return gpSwaggerPlaceHolder; }
@Bean public static PropertySourcesPlaceholderConfigurer properties(ResourceLoader resourceLoader) { PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer(); YamlPropertiesFactoryBean yaml = AlienYamlPropertiesFactoryBeanFactory.get(resourceLoader); propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject()); return propertySourcesPlaceholderConfigurer; }
@Bean public static PropertySourcesPlaceholderConfigurer properties() throws IOException { AppDataRootInitializer.init(); PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Resource[] resources = new Resource[] { new FileSystemResource( AppDataRootProvider.getAppDataRoot().toString() + File.separator + "molgenis-server.properties"), new ClassPathResource("/molgenis.properties") }; pspc.setLocations(resources); pspc.setFileEncoding("UTF-8"); pspc.setIgnoreUnresolvablePlaceholders(true); pspc.setIgnoreResourceNotFound(true); pspc.setNullValue("@null"); return pspc; }
@Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { PropertySourcesPlaceholderConfigurer p = new PropertySourcesPlaceholderConfigurer(); p.setLocation(new ClassPathResource("your properties path")); // other properties return p; }
@Bean public static PropertySourcesPlaceholderConfigurer properties(){ PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Resource[] resources = new ClassPathResource[ ] { new ClassPathResource( "foo.properties" ) }; pspc.setLocations( resources ); //pspc.setIgnoreUnresolvablePlaceholders( true ); return pspc; }
@Test public void localPropertiesViaResource() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${my.name}") .getBeanDefinition()); PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer(); Resource resource = new ClassPathResource("PropertySourcesPlaceholderConfigurerTests.properties", this.getClass()); ppc.setLocation(resource); ppc.postProcessBeanFactory(bf); assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo")); }
public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholderConfigurer() { PropertySourcesPlaceholderConfigurer properties = new PropertySourcesPlaceholderConfigurer(); properties.setLocations(new ClassPathResource[]{ new ClassPathResource("config/file1.properties"), new ClassPathResource("config/file2.properties") }); properties.setLocalOverride(true); properties.setBeanName("beanName"); properties.setIgnoreResourceNotFound(true); return properties; }
@Bean public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() throws IOException { String profile = System.getProperty("spring.profiles.active"); PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Resource resource = new ClassPathResource(String.format("application-%s.properties", profile)); Properties props = PropertiesLoaderUtils.loadProperties(resource); pspc.setProperties(props); pspc.setPropertySources(); return pspc; }
PropertySourcesPlaceholderConfigurer propertyHolder = new PropertySourcesPlaceholderConfigurer(); ConfigurableEnvironment env = new StandardEnvironment(); env.getPropertySources().addFirst( new ResourcePropertySource(new ClassPathResource( "SpringConfig.properties"))); propertyHolder.setEnvironment(env); context.addBeanFactoryPostProcessor(propertyHolder); context.register(SpringConfig.class); context.refresh();