zoukankan      html  css  js  c++  java
  • [Spring boot] CommandLineRunner and Autowired

    Previously we use Application Context to get Bean and Dependenies injection. It is actually easier to use 'CommonLineRunner'.

    Main beneift is we can use @Autowired.

    @SpringBootApplication
    public class SpringAopApplication implements CommandLineRunner{
        
        private Logger logger = LoggerFactory.getLogger(this.getClass());
    
        @Autowired
        private Business1 business1;
    
        @Autowired
        private Business2 business2;
        
        public static void main(String[] args) {
            SpringApplication.run(SpringAopApplication.class, args);
        }
    
        @Override
        public void run(String... args) throws Exception {
            logger.info(business1.calculateSomething());
            logger.info(business2.calculateSomething());
        }
    }
  • 相关阅读:
    2021/3/12
    2021/3/11
    2021/3/10
    2021/3/9
    2021/3/8
    2021/3/5
    2021/3/4
    2021/3/3
    2021/3/2
    2021/3/1
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10865277.html
Copyright © 2011-2022 走看看