Skip to content

CloudOptions 配置参考

This content is not available in your language yet.

本文档详细说明 CloudOptions 的所有配置参数及其使用方法。

CloudOptions 是 Feat Cloud 服务的核心配置类,继承自 ServerOptions,因此支持 ServerOptions 中的所有配置项(如端口、线程池、SSL 等)。

CloudOptions extends ServerOptions

指定 Feat Cloud 启动时扫描的包路径数组。

属性
类型String[]
默认值null(扫描所有包)
必填

用途:限制组件扫描范围以提升启动性能。

示例

FeatCloud.cloudServer(options -> {
options.setPackages(
"com.example.controller",
"com.example.service"
);
}).listen();

向容器中注册外部 Bean 实例。

属性
方法签名public CloudOptions registerBean(String key, Object value)
返回值CloudOptions(支持链式调用)
必填

用途:集成第三方组件或手动创建的 Bean 实例。

示例

FeatCloud.cloudServer(options -> {
options.registerBean("dataSource", createDataSource());
options.registerBean("redisTemplate", createRedisTemplate());
options.registerBean("mqProducer", createMQProducer());
}).listen();

指定静态资源文件的存放位置。

属性
类型String
默认值"classpath:static"
必填

用途:配置静态 HTML、CSS、JavaScript 等资源的根路径。

示例

// 使用默认路径
FeatCloud.cloudServer().listen();
// 自定义类路径
FeatCloud.cloudServer(options -> {
options.setStaticLocations("classpath:assets");
}).listen();
// 使用文件系统路径
FeatCloud.cloudServer(options -> {
options.setStaticLocations("file:/var/www/static");
}).listen();

public class Application {
public static void main(String[] args) {
FeatCloud.cloudServer(options -> {
// 配置扫描包
options.setPackages("com.example");
// 注册外部 Bean
options.registerBean("dataSource", DataSourceBuilder.create()
.url("jdbc:mysql://localhost:3306/test")
.username("root")
.password("password")
.build());
// 配置静态资源路径
options.setStaticLocations("classpath:public");
}).listen();
}
}
tech.smartboot.feat.core.common.exception.FeatException: bean dataSource already exists

解决方案:使用唯一名称,添加业务前缀。

若配置的包路径不存在,扫描结果为空,组件可能无法加载。建议在配置前验证包路径有效性。

CloudOptions 继承自 ServerOptions,因此也支持以下常用配置:

配置项说明
port服务端口,默认 8080
threadNum线程池大小
readBufferSize读缓冲区大小
writeBufferSize写缓冲区大小

详见 ServerOptions 配置参考