The Problem:
Hello i'm having a problem on java EE , i have to use annotation like @Inject @Stateless etcetc, but i can't get a solution, after reading a lot of documentation and example etcetc it seems that what i 've code should work but definitly not. So the problem is that i have a custom qualifiers on an interface like this
@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
public @interface BudgetsDs {
}
and i want inject it in another object as a member field like this
@Dependent
public class BudgetService {
@BudgetsDs
@Inject
DataSource budgetsDS;
... some getter, setter , etcetc...
}
i've pass through this
https://docs.oracle.com/javaee/6/tutorial/doc/gjbck.html
and other kind of documentation similar to this one. I'v tried with @EJB , @Stateless but it doesn't work. I think that i'm currently missing a big thing on the annotation, so if you have good tutorials , or good advice, or explanation i want to hear them. I don't ask for a complete answer but i would like to have at least some clue. Anyone is welcome to help.
Edit: the exact error is on the line
@BudgetsDs
@Inject
DataSource budgetsDS;
budgetDS throw Unsatisfied Dependency: no bean matches the injection point
Edit2: The solution
1) I'v implemented a new class ResourceProducer As suggested by John Ament i use @Produces and @Resource(name="jdbc/myDataSource"), for each DataSource that i need.
public class ResourceProducer {
@Produces
@BudgetsDs
@Resource(name="jdbc/BudgetsDs")
public DataSource budgetsDs;
@Produces
@OtherDs
@Resource(name="jdbc/OtherDs")
public DataSource otherDs;
...
}
2) The different custom qualifier for every connection
// In a file
@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
public @interface BudgetsDs {
}
// In a another file
@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
public @interface OtherDs {
}
3) This way the inject works well and i can inject the different DataSource where i want, like this :
@Dependent
public class BudgetService {
@BudgetsDs
@Inject
DataSource budgetsDS;
@OtherDs
@Inject
DataSource otherDs;
... some getter, setter , etcetc...
}
There is another solution Below, that works too.
Thanks to aribeiro and John Ament. My first question on stack overflow, and really well answered by the community