首页 > 移动平台 > 详细

@SpringBootApplication-exclude和扫描并装配其他包下的bean(@AliasFor)

时间:2019-10-19 23:20:09      阅读:617      评论:0      收藏:0      [点我收藏+]

1、exclude

不装配指定bean

@SpringBootApplication(exclude={com.ebc.User.class})

 

2、scanBasePackages

技术分享图片

package com.ebc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//scanBasePackages 后边的值,是一个数组。即可指定多个不同的包
@SpringBootApplication(scanBasePackages = "com.yst")
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

 

package com.yst;

import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;

@Configuration
public class WebConfiguration {
    /**
     * 浏览器地址栏中输入:http://localhost:8080/hello-world,回车后,输出: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());
        };
    }
}

运行http://localhost:8080/hello

输出:Hello,遥远2

说明,成功。

 

@SpringBootApplication-exclude和扫描并装配其他包下的bean(@AliasFor)

原文:https://www.cnblogs.com/yaoyuan2/p/11706071.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!