Announcement Announcement Module
Collapse
No announcement yet.
@Autowired @Qualifier value from place holder Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Autowired @Qualifier value from place holder

    Hi,

    I'm using Spring 3.0.4.
    I'm trying to autowire a service by retrieving the @Qualifier value from a placeholder.
    This way I can switch between the real-life implementation and the mock implementation, just by changing the value in the property file (so no compilation needs to be done).

    This is what I have so far:
    Interface:
    Code:
    public interface Service {...}
    Mock Implementation:
    Code:
    @Service("serviceMock")
    public class ServiceMock implements Service {...}
    Real-life Implementation:
    Code:
    @Service("serviceImpl")
    public class ServiceImpl implements Service {...}

    Autowire Service:
    Code:
    ...
    @Autowired
    @Qualifier("${service.implementation}")
    private Service service;
    ...
    common.properties:
    Code:
    ...
    service.implementation=serviceMock
    ...
    So by changing the service.implementation value to serviceImpl I could switch from the Mock impl to the real-life impl.

    Server startup fails and I get the message that there is no bean found with name: ${service.implementation}

    Any idea where I'm going wrong or does @Qualifier not allow expressions?

    Jeroen

  • #2
    I think @Qualifier annotation processor is not designed with the built-in capability of resolving SpEL, even though this would be a nice feature to add. Maybe you could open a Jira issue on this one; if it gets enough votes, Spring team might consider developing this feature in future versions of the framework.

    Comment

    Working...
    X