是否有任何方式注入(EJB,比如说)知道自己的注入点?
@Stateless
public class SomeService {
@PostConstruct
private void constructed() {
// do post construction job
// according to the injectionPoint
}
@Context
private InjectionPoint injectionPoint; // is this possible?
}
答案 0 :(得分:4)
如果您使用CDI注入EJB(使用@Inject
)并且它具有默认范围(没有显式范围或@Dependent
)。
您可以注入其注入点:
@Stateless
public class SomeService {
@PostConstruct
private void constructed() {
// do post construction job
// according to the injectionPoint
}
@Inject
private InjectionPoint injectionPoint; // this is possible
}