java - Auto-wiring Spring constructor arguments from properties file in XML -
I'm using Spring-Auto-Wire Beans for configuration. Some parameter properties come from the file:
& lt; Bean id = "mydb" class = "myproject.mydb" autowire = "constructor" & gt; & Lt; Constructor-arg name = "host" value = "$ {mydb.host}" /> & Lt; Constructor-arg name = "db" value = "$ {mydb.db}" /> & Lt; Constructor-Arg Name = "User" value = "$ {mydb.user}" /> & Lt; Constructor-arg name = "password" value = "$ {mydb.password}" /> & Lt; / Bean & gt; Is there a way to auto-wire these properties based on the Bean id , so that I have to write the following? & lt; Bean id = "mydb" class = "myproject.mydb" autowire = "constructor" /> Edit: This means that there is a need to clarify the constructor arguments without any equals. Automatically scan properties for beanId.constructorArgName
Wish what you really want, I think you will need to implement the BeanPostProcessor and your custom wiring logic in postProcessBeforeInitialization (where you read the .properties file ) give. Been name is available for that method, but there are many problems with it. The first argument is logic, so indexed can be a better option. The second is that you already have an instant bean (hence a default constructor will be required), and you want to instantate the other, throwing a first one which is worthless to use an example that already exists, You need to wire it with properties, not constructor, which violates encapsulation and that is not what you asked. The third is that it is not absolutely clear what is going on. So, everything, you are perfectly better in avoiding it.
Comments
Post a Comment