@SpringBootApplication 标注非引导类

1、引导类

public class App {
    public static void main(String[] args) {
        SpringApplication.run(WebConfiguration.class, args);
    }
}

2、WebConfiguration 

@SpringBootApplication
public class WebConfiguration {
    /**
     * 浏览器地址栏中输入:http://localhost:8080/hello,回车后,输出:Hello,World
     * @return
     */
    @Bean
    public RouterFunction<ServerResponse> helloworld() {
        return route(GET("/hello"),request->ok().body(Mono.just("Hello,遥远2"),String.class));
    }

    /**
     * 在spring boot应用启动后回调
     * @param context
     * @return
     */
    @Bean
    public ApplicationRunner runner(WebServerApplicationContext context) {
        return args -> {
            System.out.println("当前WebServer实现类为:"+context.getWebServer().getClass().getName());
        };
    }
}

也可以正常运行。

见《springboot-05-SpringBootApplication-03-tagnoapp》

 

posted @ 2019-10-25 22:36  遥远2  阅读(252)  评论(0编辑  收藏  举报