views:

90

answers:

2

I have some JDO objects that I want to spring to configure with info from a property file.

But since spring isn't used to create (i.e these objects are not listed as beans in the xml. Should they, how would it look?) these objects how can I get it to configure those objects?

Only solution I can come up with is to have the property file info configured into the dao and then have the dao insert that data into the object before it returns it. Or I guess I can do some AOP magic, but that seems heavy handed and I don't think it will work in Google App Engine where this service will be deployed.

Any other advice.

A: 

You can put any bean in applicationContext.xml, and configure all of its properties there. The properties file can be loaded via:

<context:property-placeholder location="classpath:application.properties" />

and then, on your bean definition:

<property name="propertyName" value="${valueFromPropertiesFile}" />

Then, in order to have the properly configured bean, you will have to inject it - either in the applicationContext.xml, or via @Resource / @Autowired

But if you can't let spring create, and configure your beans, then simply populate them with your properties manually - load a properties file with java.util.Properties, and fill the data needed.

Bozho
The JDO object couldn't be injected, it is created by the DAO and there will be more than one so how could spring know which to inject?
arinte
well, then you can't use spring. You must fill your objects at the moment you instantiated them. Load your properties manually.
Bozho
He could actually by providing a stateful Spring bean factory. However usually that sort of things falls under the category of forcing the use of technology for the sake of the technology itself instead of actual need so I wouldn't recommend it.
Esko
yes, you are correct. instantiating domain objects from within a managed context is not a common practice, I think.
Bozho
A: 

I have some JDO objects that I want to spring to configure with info from a property file.

I don't get the whole idea. Are these objects persistent or not? If they are, just load them from the datastore. If not, they aren't really JDO objects as pointed out in comments. And in that case, I don't understand the point of the DAO and of the property file. Why don't you just declare them as Spring beans?

Pascal Thivent