The World’s Largest Online Community for Developers

'; Defining a template for custom annotations in Java for dependency injection - LavOzs.Com

I want to define custom annotations for a set of Strings that I will inject as class fields. Currently, my Spring IoC container class looks like this-

public class DependencyConfig {

    public @interface FooInterface {}

    public String foo() { return "Foo" }

    public @interface BarInterface {}

    public String foo() { return "Bar" }

    public @interface FooBarInterface {}

    public String foo() { return "FooBar" }

I don't like that I have to separately define all the annotations with the same attributes. Is there a way to shorten this code but still have individual annotation types like @Foo, @Bar and @FooBar?

What is dependency injection?
What are the benefits of dependency injection containers?
Dependency Injection vs Factory Pattern
How to use log4net with Dependency Injection
Injecting Mockito mocks into a Spring bean
Which @NotNull Java annotation should I use?
Java Dependency injection: XML or annotations
Inversion of Control vs Dependency Injection
Why does one use dependency injection?