Created
February 12, 2014 18:20
-
-
Save K0NRAD/8961480 to your computer and use it in GitHub Desktop.
Jave EE usage of @qualifier #- create type enum #- create qualifier annotation #- create service interface #- create implementations of service interface #- inject and use qualifier annotation to specify the correct service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum EProductivityPlanType { | |
TARGET, ACTUAL | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IProductivityPlan { | |
void calculate(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ProductivityPlanType(type = EProductivityPlanType.ACTUAL) | |
public class ProductivityPlanActual implements IProductivityPlan { | |
@Override | |
public void calculate() { | |
// calculate actual productivity plan | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ProductivityPlanType(type = EProductivityPlanType.TARGET) | |
public class ProductivityPlanTarget implements IProductivityPlan { | |
@Override | |
public void calculate() { | |
// calculate target productivity plan | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Qualifier | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) | |
public @interface ProductivityPlanType { | |
EProductivityPlanType type() default EProductivityPlanType.TARGET; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
@Inject | |
@ProductivityPlanType(type = EProductivityPlanType.TARGET) | |
private IProductivityPlan productivityPlanTarget; | |
@Inject | |
@ProductivityPlanType(type = EProductivityPlanType.ACTUAL) | |
private IProductivityPlan productivityPlanActual; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment