@Controller public class HelloController { private AlphaService alphaService; private BetaService betaService; @Autowired public void setAlphaService(AlphaService alphaService) { this.alphaService = alphaService; } @Autowired public void setBetaService(BetaService betaService) { this.betaService = betaService; } }
普通实现方法
@Controller public class HelloController { private final AlphaService alphaService; private final BetaService betaService; @Autowired public HelloController(AlphaService alphaService, BetaService betaService) { this.alphaService = alphaService; this.betaService = betaService; } }
lombok注解方式
@AllArgsConstructor @Controller public class HelloController { private final AlphaService alphaService; private final BetaService betaService; }
@Controller public class HelloController { @Autowired private AlphaService alphaService; @Autowired private BetaService betaService; }