@Required publicvoidsetCollaborator(Collaborator c) { this.collaborator = c; } }
或者
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
publicclassServiceimplementsInitializingBean {
private Collaborator collaborator;
publicvoidsetCollaborator(Collaborator c) { this.collaborator = c; }
// from the InitializingBean interface publicvoidafterPropertiesSet() { if (collaborator == null) { thrownewIllegalStateException("Collaborator must be set in order for service to work"); } } }