本文整理汇总了Java中org.springframework.beans.factory.config.PropertyPlaceholderConfigurer类的典型用法代码示例。如果您正苦于以下问题:Java PropertyPlaceholderConfigurer类的具体用法?Java PropertyPlaceholderConfigurer怎么用?Java PropertyPlaceholderConfigurer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PropertyPlaceholderConfigurer类属于org.springframework.beans.factory.config包,在下文中一共展示了PropertyPlaceholderConfigurer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultExpressionParameters
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void defaultExpressionParameters() throws Exception {
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
@Override
public void initialize(GenericWebApplicationContext context) {
RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
ppc.getPropertyValues().add("properties", "myKey=foo");
context.registerBeanDefinition("ppc", ppc);
}
}, DefaultExpressionValueParamController.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myPath.do");
request.setContextPath("/myApp");
MockHttpServletResponse response = new MockHttpServletResponse();
System.setProperty("myHeader", "bar");
try {
getServlet().service(request, response);
}
finally {
System.clearProperty("myHeader");
}
assertEquals("foo-bar-/myApp", response.getContentAsString());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:ServletAnnotationControllerHandlerMethodTests.java
示例2: verifyEmbeddedConfigurationContext
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void verifyEmbeddedConfigurationContext() {
final PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
final Properties properties = new Properties();
properties.setProperty("mongodb.host", "ds061954.mongolab.com");
properties.setProperty("mongodb.port", "61954");
properties.setProperty("mongodb.userId", "casuser");
properties.setProperty("mongodb.userPassword", "Mellon");
properties.setProperty("cas.service.registry.mongo.db", "jasigcas");
configurer.setProperties(properties);
final FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
new String[]{"src/main/resources/META-INF/spring/mongo-services-context.xml"}, false);
ctx.getBeanFactoryPostProcessors().add(configurer);
ctx.refresh();
final MongoServiceRegistryDao dao = new MongoServiceRegistryDao();
dao.setMongoTemplate(ctx.getBean("mongoTemplate", MongoTemplate.class));
cleanAll(dao);
assertTrue(dao.load().isEmpty());
saveAndLoad(dao);
}
示例3: applyDefaultOverrides
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Override
protected void applyDefaultOverrides(PropertyBackedBeanState state) throws IOException
{
// Let the superclass propagate default settings from the global properties and register us
super.applyDefaultOverrides(state);
List<String> idList = getId();
// Apply any property overrides from the extension classpath and also allow system properties and JNDI to
// override. We use the type name and last component of the ID in the path
JndiPropertiesFactoryBean overrideFactory = new JndiPropertiesFactoryBean();
overrideFactory.setPropertiesPersister(getPersister());
overrideFactory.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
overrideFactory.setLocations(getParent().getResources(
ChildApplicationContextFactory.EXTENSION_CLASSPATH_PREFIX + getCategory() + '/' + getTypeName() + '/'
+ idList.get(idList.size() - 1) + ChildApplicationContextFactory.PROPERTIES_SUFFIX));
overrideFactory.setProperties(((ApplicationContextState) state).properties);
overrideFactory.afterPropertiesSet();
((ApplicationContextState) state).properties = (Properties) overrideFactory.getObject();
}
示例4: ChildApplicationContext
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
/**
* The Constructor.
*
* @param properties
* the properties
* @param compositeProperties
* the composite properties
* @throws BeansException
* the beans exception
*/
private ChildApplicationContext(Properties properties,
Map<String, Map<String, CompositeDataBean>> compositeProperties) throws BeansException
{
super(getContextResourcePatterns(), false, ChildApplicationContextFactory.this.getParent());
this.compositeProperties = compositeProperties;
// Add a property placeholder configurer, with the subsystem-scoped default properties
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
configurer.setPropertiesArray(new Properties[] {ChildApplicationContextFactory.this.getPropertyDefaults(), properties});
configurer.setIgnoreUnresolvablePlaceholders(true);
configurer.setSearchSystemEnvironment(false);
addBeanFactoryPostProcessor(configurer);
setClassLoader(ChildApplicationContextFactory.this.getParent().getClassLoader());
}
示例5: configurationWithPostProcessor
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void configurationWithPostProcessor() {
AnnotationConfigApplicationContext factory = new AnnotationConfigApplicationContext();
factory.register(ConfigWithPostProcessor.class);
RootBeanDefinition placeholderConfigurer = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
placeholderConfigurer.getPropertyValues().add("properties", "myProp=myValue");
factory.registerBeanDefinition("placeholderConfigurer", placeholderConfigurer);
factory.refresh();
TestBean foo = factory.getBean("foo", TestBean.class);
ITestBean bar = factory.getBean("bar", ITestBean.class);
ITestBean baz = factory.getBean("baz", ITestBean.class);
assertEquals("foo-processed-myValue", foo.getName());
assertEquals("bar-processed-myValue", bar.getName());
assertEquals("baz-processed-myValue", baz.getName());
SpousyTestBean listener = factory.getBean("listenerTestBean", SpousyTestBean.class);
assertTrue(listener.refreshed);
}
示例6: testMultipleDefinedBeanFactoryPostProcessors
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void testMultipleDefinedBeanFactoryPostProcessors() {
StaticApplicationContext ac = new StaticApplicationContext();
ac.registerSingleton("tb1", TestBean.class);
ac.registerSingleton("tb2", TestBean.class);
MutablePropertyValues pvs1 = new MutablePropertyValues();
pvs1.add("initValue", "${key}");
ac.registerSingleton("bfpp1", TestBeanFactoryPostProcessor.class, pvs1);
MutablePropertyValues pvs2 = new MutablePropertyValues();
pvs2.add("properties", "key=value");
ac.registerSingleton("bfpp2", PropertyPlaceholderConfigurer.class, pvs2);
ac.refresh();
TestBeanFactoryPostProcessor bfpp = (TestBeanFactoryPostProcessor) ac.getBean("bfpp1");
assertEquals("value", bfpp.initValue);
assertTrue(bfpp.wasCalled);
}
示例7: propertyPlaceholderSystemProperties
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void propertyPlaceholderSystemProperties() throws Exception {
String value = System.setProperty("foo", "spam");
try {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"contextNamespaceHandlerTests-system.xml", getClass());
Map<String, PropertyPlaceholderConfigurer> beans = applicationContext
.getBeansOfType(PropertyPlaceholderConfigurer.class);
assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty());
assertEquals("spam", applicationContext.getBean("string"));
assertEquals("none", applicationContext.getBean("fallback"));
}
finally {
if (value != null) {
System.setProperty("foo", value);
}
}
}
示例8: testFormatFieldForValueInjectionUsingMetaAnnotations
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
@SuppressWarnings("resource")
public void testFormatFieldForValueInjectionUsingMetaAnnotations() {
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
RootBeanDefinition bd = new RootBeanDefinition(MetaValueBean.class);
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
ac.registerBeanDefinition("valueBean", bd);
ac.registerBeanDefinition("conversionService", new RootBeanDefinition(FormattingConversionServiceFactoryBean.class));
ac.registerBeanDefinition("ppc", new RootBeanDefinition(PropertyPlaceholderConfigurer.class));
ac.refresh();
System.setProperty("myDate", "10-31-09");
System.setProperty("myNumber", "99.99%");
try {
MetaValueBean valueBean = ac.getBean(MetaValueBean.class);
assertEquals(new LocalDate(2009, 10, 31), new LocalDate(valueBean.date));
assertEquals(Double.valueOf(0.9999), valueBean.number);
}
finally {
System.clearProperty("myDate");
System.clearProperty("myNumber");
}
}
示例9: testScanWithExplicitSqlSessionFactoryViaPlaceholder
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void testScanWithExplicitSqlSessionFactoryViaPlaceholder() throws Exception {
setupSqlSessionFactory("sqlSessionFactory2");
// use a property placeholder for the session factory name
applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
"sqlSessionFactoryBeanName", "${sqlSessionFactoryBeanNameProperty}");
Properties props = new java.util.Properties();
props.put("sqlSessionFactoryBeanNameProperty", "sqlSessionFactory2");
GenericBeanDefinition propertyDefinition = new GenericBeanDefinition();
propertyDefinition.setBeanClass(PropertyPlaceholderConfigurer.class);
propertyDefinition.getPropertyValues().add("properties", props);
applicationContext.registerBeanDefinition("propertiesPlaceholder", propertyDefinition);
testInterfaceScan();
}
示例10: getPropertyPlaceholderConfigurer
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
/**
* 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;
}
示例11: propertyPlaceholderConfigurer
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
final PropertyPlaceholderConfigurer propConfig =
new PropertyPlaceholderConfigurer();
propConfig.setIgnoreResourceNotFound(true);
String sysPropPath = System.getProperty("app.cfg");
if (sysPropPath != null) {
propConfig.setLocation(new FileSystemResource(sysPropPath));
} else {
propConfig.setLocation(new ClassPathResource(APP_PROPERTIES));
}
return propConfig;
}
示例12: propertyPlaceholderConfigurer
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
/**
* Property placeholder configurer.
*
* @return the property placeholder configurer
*/
@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
final List<Resource> resourceLst = new ArrayList<>();
resourceLst.add(new ClassPathResource("/hibernateTest.properties"));
resourceLst.add(new ClassPathResource("/config.properties"));
resourceLst.add(new ClassPathResource("/bankRemittance.properties"));
resourceLst.add(new ClassPathResource("/firebaseMessaging.properties"));
resourceLst.add(new ClassPathResource("/firebaseWeb.properties"));
resourceLst.add(new ClassPathResource("/paypal.properties"));
resourceLst.add(new ClassPathResource("/recaptcha.properties"));
//initializeFirebase("configFirebase", "/members-firebase-adminsdk.json");
ppc.setLocations(resourceLst.toArray(new Resource[] {}));
return ppc;
}
示例13: testPropertyPlaceholderConfigurerWithSystemPropertyInLocation
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void testPropertyPlaceholderConfigurerWithSystemPropertyInLocation() {
StaticApplicationContext ac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
ac.registerSingleton("tb", TestBean.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("location", "${user.dir}/test");
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
try {
ac.refresh();
fail("Should have thrown BeanInitializationException");
}
catch (BeanInitializationException ex) {
// expected
assertTrue(ex.getCause() instanceof FileNotFoundException);
// slight hack for Linux/Unix systems
String userDir = StringUtils.cleanPath(System.getProperty("user.dir"));
if (userDir.startsWith("/")) {
userDir = userDir.substring(1);
}
assertTrue(ex.getMessage().indexOf(userDir) != -1);
}
}
示例14: testPropertyPlaceholderConfigurerWithUnresolvableSystemPropertiesInLocation
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void testPropertyPlaceholderConfigurerWithUnresolvableSystemPropertiesInLocation() {
StaticApplicationContext ac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
ac.registerSingleton("tb", TestBean.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("location", "${myprop}/test/${myprop}");
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
try {
ac.refresh();
fail("Should have thrown BeanInitializationException");
}
catch (BeanInitializationException ex) {
// expected
assertTrue(ex.getMessage().contains("myprop"));
}
}
示例15: testPropertyPlaceholderConfigurerWithMultiLevelCircularReference
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void testPropertyPlaceholderConfigurerWithMultiLevelCircularReference() {
StaticApplicationContext ac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "name${var}");
ac.registerSingleton("tb1", TestBean.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${var}");
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
try {
ac.refresh();
fail("Should have thrown BeanDefinitionStoreException");
}
catch (BeanDefinitionStoreException ex) {
// expected
}
}