在spring boot 中有一段代码,使用的是java 1.8的语法:

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
        return args -> {

            System.out.println("Let's inspect the beans provided by Spring Boot:");

            String[] beanNames = ctx.getBeanDefinitionNames();
            Arrays.sort(beanNames);
            for (String beanName : beanNames) {
                System.out.println(beanName);
            }

        };
    }

在java 1.7下要如何使用呢?

    @Bean
    public CommandLineRunner commandLineRunner(final ApplicationContext ctx) {
        return new CommandLineRunner() {
            public void run(String[] args) {
                System.out.println("Let's inspect the beans provided by Spring Boot:");
                String[] beanNames = ctx.getBeanDefinitionNames();
                Arrays.sort(beanNames);
                for (String beanName : beanNames) {
                    System.out.println(beanName);
                }
            }
        };
    }

相关文章:

  • 2021-10-01
  • 2021-12-13
  • 2022-12-23
  • 2021-11-01
  • 2021-09-23
猜你喜欢
  • 2022-01-14
  • 2021-05-04
  • 2022-01-29
  • 2022-12-23
  • 2022-01-13
  • 2021-06-27
  • 2023-03-28
相关资源
相似解决方案