View Poll Results: @Autowired @Qualifier value from place holder

Voters
0. You may not vote on this poll
  • @Autowired @Qualifier

    0 0%
  • @Autowired @Qualifier value from place holder

    0 0%
  • @Qualifier value from placeholder

    0 0%
Multiple Choice Poll.
Results 1 to 2 of 2

Thread: @Autowired @Qualifier value from place holder issue

  1. #1

    Default @Autowired @Qualifier value from place holder issue

    Hi,
    I'm using Spring 3.0.4 and trying to autowire a service by retrieving the @Qualifier value from a placeholder(a property file). This way i can switch between the Real service implementation and the mock implementation, just by changing the value in the property file. By doing so i want to avoid recompilation of code.

    Below is my sample codes :



    Integration Layer



    Interface:

    Code:
         public interface Service { ....... }

    Mock Implementation :

    Code:
      
         @Service("mockService")
         public class MockService implements Service { ....... }

    Real-Service Implementation :

    Code:
        @Service("realService")
        public class ServiceImpl implements Service { ....... }





    Business Service Layer



    Autowire service:

    Code:
    .....
    @Autowired
    @Qualifier("${service.real}")
    private Service service;
    .....

    qualifier.properties:
    Code:
    .....
    service.real=mockService
    .....



    The above idea is to change the service.real value to service.real, by doing so i can switch from Mock implementation to Real Implementation.

    During server startup it fails and message is displayed saying no bean found with name: ${service.real}

    Any Idea how to resolve this issue or alternate way to achieve this functionality using @Qualifier ?
    Last edited by SharathKumarS; Jul 24th, 2012 at 12:01 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Why is this a poll? And when posting code use [ code][/code ] tags so that it remains readable.

    Placeholders in @Qualifier isn't (yet) supported not sure if SpEL is either. This has to do with the way these annotations are processed, you could try and register a enhancement JIRA for it. Also instead of this you might want to try profiles (assuming you are on Spring 3.1) that way you can easily switch between components depending on environment.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •