开发者

Spring, db and property file configuration

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开发者_如何学JAVA 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.


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜