Read value from config in Spring

Tags: xml spring config

This might be a way to simple question, but I seem to miss the right google-words 8/ Does Spring 3 have a way to read an arbitrary value from any of the xml-config-files? Meaning, I'd just like to read a value, not having Spring set up anything according to it.

Thanx in advance, Marcus


mentioning, that I'm new to Java beforehand, I'd like to have some like <DatabaseType>MYSQL</DatabaseType> inside any of the configs, that are processed by Spring and would like to access them inside of any Java-class.

Why would I want that? I have a basic SWT/JFace fronted (working) and a DAO-layer (working, too). Now, I'm thinking about the services in the middle. Currently, my service has something like 'MYSQL' hardcoded to instantiate the DAO-factory. But that would couple the service directly to MYSQL in that case, thus ruining the whole decoupling-efforts. So, to abstract that as well, I'd go for an abstract factory for the services aswell. But to decide on some parameters, I'd have to read those out of some config. As Spring already does that, I'd feel it to be nonsense to implement that separately.


Spring is mainly a Dependency-Injection framework - so if you need a value from the configuration somewhere in your application you should spring let inject it into your class.

Have a look at the documentation, e.g. Dependencies and configuration in detail.

By : FrVaBe

This video can help you solving your question :)
By: admin