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

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

说明,成功。

猜你喜欢

转载自www.cnblogs.com/yaoyuan2/p/11706071.html