Difference between @Bean and @Autowired

前端 未结 6 1815
小蘑菇
小蘑菇 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:44

    great answer by @DaveyDaveDave In the example instead of

    @Bean
      BookingService bookingService() {
        return new BookingService();
      }
    

    You can use @Service annotation on BookingService class

提交回复
热议问题