|
#1
|
|||
|
|||
|
Hi folks,
I have an application that runs via Webstart that I just added a version.properties file to. I have several Spring context files that get loaded in various configurations depending on whether the application is deployed in JBoss or is being executed for development purposes. When loading via Webstart from JBoss, there are two different PropertyPlaceholderConfigurer objects that get instantiated. One is a custom extension to get the codebase of the JNLP file and use it as the service URL for remoting purposes. The other is meant to load the version.properties and inject those values into an information bean. The problem is that for some reason the application says it cannot find a value for the placeholder for which the versio properties are being loaded. I was wondering if there is any reason why I cannot have two different PropertyPlaceholderConfigurer objects? I don't see any such statement in the API - at least, nothing explicit. It's almost as if the version.properties file cannot be found on the classpath, but all of the rest of the files can. I have verified that the jar file containing it is indeed in the JWS cache. Thanks, David |
|
#2
|
||||
|
||||
|
There is no restriction on the number of PropertyPlaceholderConfigurer objects - you can have as many as you like. However you have to determine the order in each they are called (usually it's the declaration order).
The first configurer might override some properties which cannot be later on retrieved by the last configurer for example. This being said you might have some classloading problems - where do you want to load your version.properties from?
__________________
Costin Leau SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source" http://twitter.com/costinl Please use [ c o d e ] [ / c o d e ] tags |
|
#3
|
|||
|
|||
|
The behavior certainly leads me to believe that the version.properties file cannot be found on the classpath, but since all of the Spring context files are in the same location and they load fine that seems like a reach.
My custom configurer overrides the loadProperties method and sets a property in the provided "props" argument based on the codeBase system property set by Java Webstart from the JNLP file. That's all it does. And it loads first. Next, the gui-context.xml file tries to load the "version.properties" file... <bean id="guiPropertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:version.properties</value> </list> </property> </bean> As soon as I encounter an object that uses one of the properties in that file as a placeholder, I get a BeanDefinitionStoreException saying it cannot resolve the placeholder. There doesn't seem to be any error indicating that it could not load the properties into the configurer, though. Does that help? |
|
#4
|
|||
|
|||
|
I cannot explain why this happens, but I have solved my immediate problem. I simply re-ordered the list of context.xml files that are being loaded so that I could use a single PropertyPlaceholderConfigurer in the first one and let all of the properties flow through to the rest of the context files. It works.
I guess having more than one creates some kind of strange collision in which the second one cannot successfully load properties from a file. |
|
#5
|
|||
|
|||
|
if you have more than one PropertyPlaceholderConfigurer.
you need to know which one is loaded first. and set "ignoreUnresolvablePlaceholders" property to true for it: <property name="ignoreUnresolvablePlaceholders" value="true"/> or else it will not allow for second PropertyPlaceholderConfigurer to load. |
|
#6
|
|||
|
|||
|
Awesome! That's exactly what I needed! Thanks!
|
|
#7
|
|||
|
|||
|
Quote:
- Need to know the order in which the PPC are loaded, and set all but the last one to ignoreUnresolvablePlaceholders - Set all PPC to ignore unresolvable placeholders. I have an application that weaves these files in an unspecified order, so the only option is to set ignore on all. Then I won't know at all if a placeholder that aren't resolved is encountered after all files are loaded. I'm setting up several context-files using a beanRefContext.xml, and I would like to know after all context-files have been loaded if a property wasn't resolved. Any way to to this? |
|
#8
|
||||
|
||||
|
You could create your own BPP that can parse all the PropertyPlaceholderConfigurer definitions and then, on the last one found, set the ingoreUnresolvablePlaceholder to true (the rest will have by default, this property set to false).
__________________
Costin Leau SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source" http://twitter.com/costinl Please use [ c o d e ] [ / c o d e ] tags |
|
#9
|
|||
|
|||
|
Costin,
If I have several context files, and each of them has a BPP ( CustomPropertyEditor). So, there won't be any conflicts between them, if they different class-editor mappings, right? |
|
#10
|
||||
|
||||
|
I though we were talking about PropertyPlaceholders here. Anyway, when you have different xmls it depends how they are assembled - if you have a hierarchy (child/parent relationship) then each PPE belongs to the context in which it is declared. If they are assembled into one then they are just added to the factory, beans under the same name will be overriden by the last definition.
As for the PE (which is registered for a type certain class) the last definition will win. Basically, in a context you can have multiple PPE but only one PE for the same class type.
__________________
Costin Leau SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source" http://twitter.com/costinl Please use [ c o d e ] [ / c o d e ] tags |
![]() |
| Thread Tools | |
| Display Modes | |
|
|