Difference between @Bean and @Autowired

前端 未结 6 1791
小蘑菇
小蘑菇 2020-11-28 01:26

Why can\'t I use @Autowired in this case?

@SpringBootApplication
public class Application {

    @Autowired
    BookingService bookingService;

         


        
6条回答
  •  一向
    一向 (楼主)
    2020-11-28 01:48

    @Bean is just for the metadata definition to create the bean(equivalent to tag). @Autowired is to inject the dependancy into a bean(equivalent to ref XML tag/attribute).

提交回复
热议问题