问题
I have a @ConversationScoped
CDI bean with a Conversation
interface injected and access modifier set as private. Something like this:
@Named
@ConversationScoped
public class MySampleCdiBean implements Serializable {
@Inject
private Conversation conversation;
//other stuffs
}
My question is do I need a getter for this injected conversation interface? Does the CDI container need this getter? Any resource from where I can understand the underlying details of how CDI container handles a conversation would be super helpful too.
回答1:
There are multiple ways to define an injection point on the injected class. So far you have annotated the fields that reference the injected object. You do not need to provide getters and setters for field injection.
More information can be found here: https://netbeans.org/kb/docs/javaee/cdi-inject.html
hope its helpful.
来源:https://stackoverflow.com/questions/33383446/do-i-need-getter-for-the-injected-conversation-interface-in-cdi-bean