Is it possible to do a constructor-based CDI injection of a @Resource type of instance?
I have the following class:
class MyClass {
@Resource
private ManagedExecutorService executorService;
@Inject
private MyService myservice;
}
I would like to convert it into something like this:
class MyClass {
private final ManagedExecutorService executorService;
private final MyService myservice;
@Inject
MyClass(ManagedExecutorService executorService, MyService myService)
{
this.executorService = executorService;
this.myService = myService;
}
}
This would make the class immutable and easier to unit test. The problem is that since the executorService needs to be obtained via a @Resource annotation, it doesn't seem to be injectable via the constructor.