*
The moose likes Spring and the fly likes Property settings in spring-beans.xml at compile time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Property settings in spring-beans.xml at compile time" Watch "Property settings in spring-beans.xml at compile time" New topic
Author

Property settings in spring-beans.xml at compile time

Craig Taylor
Ranch Hand

Joined: Jul 17, 2008
Posts: 64
I'm needing to set some properties in spring-beans.xml at compile time without re-writing / modifying it.

I believe, the first step for this would be to pull from the context and I've added the following:

that gets invoked from the build script when creating the context.xml.

The next step is -- how can spring-beans.xml reference this paramName parameter during it's initialization?

I'm not able to initialize these parameters at startup easily, hence wanting to establish them in a list in the spring-beans.xml.

Thanks,
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Look at the PropertyPlaceholderConfigurer class. It is a PostFactoryBeanProcessor that can replace property values in xml using ${mypropery.name}

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Craig Taylor
Ranch Hand

Joined: Jul 17, 2008
Posts: 64
Mark,

I'm now getting a "Could not resolve placeholder" when I try to reference the ${propName} from within the spring-beans.xml (after having defined it in context.xml).

I did try adding a property to the pre-existing (in my code) PropertyPlaceholderConfigurer but end up getting a SAX parsing issue. Eg:



I then later reference it as ${propName} within a later property for a bean.

The PropertyPlaceholderConfigurer states that
A configurer will also check against system properties (e.g. "user.dir") if it cannot resolve a placeholder with any of the specified properties. This can be customized via "systemPropertiesMode".

which leads me to believe that the addition of the PropertyPlaceholderConfigurer.propName setting is not needed. With it, I get a SAX parsing error - without it I get a "Could not resolve placeholder".

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

No, you should not have that property tag.

Here is an example of how it should look



Or if you have just one file, the simplest way is to include the context namespace and use <context:propertyPlaceholder location="classpath:aPropFile.properties"/>

Something like that, I never memorize that stuff.

then you can access properties defined in the properties file with



as an example.

Also note Spring will not only check your properties file you defined in the file, but also will check properties you have that you can get from System.getProperty(String propName) and also actual OS system properties.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Property settings in spring-beans.xml at compile time
 
Similar Threads
unable to integrate my dao classes with spring
Classpath issue: class path resource [beans.xml] cannot be opened because it does not exist
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'id' is defined
Spliting Spring Configurations
JBoss - multiple vagueness