c******n 发帖数: 4965 | 1 it seems that there can be only one,
although the javadoc says there can be multiple.
there is a bug that makes only the first of multiple
PropertyPlaceholderConfigurer effective.
I need multiple since I want to give a default value for a placeholder in my
bean , provided by my library. if the user uses my library, the bean is
created with default behavior. otherwise if the user does not supply a
config key/val pair in his properties files, the placeholder can not be
resolved and gives an exception
have you been able to use multiple placeHolderConfigurer? | e*****t 发帖数: 1005 | 2 you can certainly have multiple, but their placeholderprefix and suffix
should be different.
my
【在 c******n 的大作中提到】 : it seems that there can be only one, : although the javadoc says there can be multiple. : there is a bug that makes only the first of multiple : PropertyPlaceholderConfigurer effective. : I need multiple since I want to give a default value for a placeholder in my : bean , provided by my library. if the user uses my library, the bean is : created with default behavior. otherwise if the user does not supply a : config key/val pair in his properties files, the placeholder can not be : resolved and gives an exception : have you been able to use multiple placeHolderConfigurer?
| g*****g 发帖数: 34805 | 3 Write your own implementation to work around this,
should be fairly simple. I remember we went through this before.
my
【在 c******n 的大作中提到】 : it seems that there can be only one, : although the javadoc says there can be multiple. : there is a bug that makes only the first of multiple : PropertyPlaceholderConfigurer effective. : I need multiple since I want to give a default value for a placeholder in my : bean , provided by my library. if the user uses my library, the bean is : created with default behavior. otherwise if the user does not supply a : config key/val pair in his properties files, the placeholder can not be : resolved and gives an exception : have you been able to use multiple placeHolderConfigurer?
| c******n 发帖数: 4965 | 4 do you remember how you circumvented this bug?
thanks
【在 g*****g 的大作中提到】 : Write your own implementation to work around this, : should be fairly simple. I remember we went through this before. : : my
| c******n 发帖数: 4965 | 5 I don't think so
if you check the following simple code
///////////////////////
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TTT {
private String p ;
public String getP() { return p;}
public void setP(String p) { this.p = p;}
public void fun() {
System.out.println("value" + p);
}
public static void main(String args[]) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"ttt.xml");
TTT o = (TTT) ctx.getBean("ttt");
o.fun();
}
}
//////////////////////////////////////////////
http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
class="org.springframework.beans.factory.config.
PropertyPlaceholderConfigurer">
p1.properties
class="org.springframework.beans.factory.config.
PropertyPlaceholderConfigurer">
p2.properties
#####################################################
now you have 2 property files, p1.properties comes first, you can see that
if you comment out everything from p1 , it throws an exception;
if p1 and p2 contents are different, the result you get depends on the order
of which PPC section is used first. assuming that these sections could be
from different libraries, and imported, then the order of import becomes
critical, which is not what we normally expect
【在 e*****t 的大作中提到】 : you can certainly have multiple, but their placeholderprefix and suffix : should be different. : : my
| r*****s 发帖数: 985 | 6 https://jira.springsource.org/browse/SPR-6428
depending on what version of spring you are using, if it is 3.1.
Per this bug log:
The alternative is to (a) use the new PropertySourcesPlaceholderConfigurer i
nstead of the traditional PropertyPlaceholderConfigurer; (b) eliminate the f
irst PPC; (c) register a PropertySource with the ApplicationContext's Enviro
nment that contains the properties for the placeholders that need replacemen
t in the PropertySourcesPlaceholderConfigurer, such as ${resourceDirPlaceHol
der} from your original example.
【在 c******n 的大作中提到】 : do you remember how you circumvented this bug? : thanks
|
|