Java – spring autowire using the types defined in the comments and properties file?

My goal is a framework in which specific types of beans can be easily changed through property files I also prefer annotations to XML Ideally, I would use a combination of @ resource and spiel, as follows:

@Resource(type="#{myProperties['enabled.subtype']}")
SomeInterface foo;

I've loaded myproperties using properties for actor bean or < util: Properties > From a file containing:

enabled.type = com.mycompany.someClassA; // which implements SomeInterface

This does not work because parameters of type must be literal, i.e. spel. Is not allowed What are the best practices here?

Update: please refer to the answers below

Solution

This is the use case of spring Java configuration

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans -java

Or you can build a factory

Use: org springframework. beans. factory. factorybean< SomeInterface>

The name of the bean that implements the factorybean will be treated as "someinterface", even if it is not

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>