@SpringBootApplication-exclude和扫描并装配其他包下的bean(@AliasFor)
2024-09-06 03:38:48
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
说明,成功。
最新文章
- 将DataTable中的某列转换成数组或者List
- 使用ssh连接gitHub
- C#事件学习
- Struts2 DomainModel、ModelDriven接收参数
- Android 自动化测试 Emmagee
- TestLink安装全攻略
- (九)play之yabe项目【发表博文】
- c# Start/Stop/Check Status远程计算机的Windows Service
- 开发基于Handoff的App(Swift)
- Valgrind简单用法
- linux内核设计与实现--从内核出发
- URI中的常用属性
- 软件工程课后作业——四则运算Ⅲ(C++)
- access数据库的连接字符串以及数据库操作类
- zookeeper数据弱一致性
- NodeJS常用模块介绍
- discuz网站数据库迁移
- Java课程设计——GUI密码生成器201521123035
- c++11の死锁
- Java最小化镜像制作