Is it possible to inject a CDI Bean into a static variable in Java EE 6?
问题 Is this possible: @Inject @MessageTransport(MessageTransportType.SMS) public static MessageSender messageSender; I'm getting a NPE when i'm trying to access this static variable. So I wonder, if it is not possible in general. Thanks in advance. 回答1: Not done in general because a static variable cannot have a scope, i.e. it's just one for the whole class (read application) and therefore it doesn't make sense since every instance would try to set it to a new value based on the current scope.