跳转到内容

CloudOptions 配置参考

CloudOptions 是 Feat Cloud 服务的核心配置类,继承自 ServerOptions,除本文档列出的特有配置外,还支持端口、线程池、SSL 等基础配置。

指定启动时扫描的包路径,用于限制组件扫描范围。

属性
类型String[]
默认值null(扫描所有包)
FeatCloud.cloudServer(options -> {
options.setPackages("com.example.controller", "com.example.service");
}).listen();

向容器注册外部 Bean 实例,注册后可通过 @Autowired 注入使用。

属性
方法签名CloudOptions registerBean(String key, Object value)
返回值CloudOptions(支持链式调用)
FeatCloud.cloudServer(options -> {
options.registerBean("dataSource", createDataSource());
options.registerBean("redisTemplate", createRedisTemplate());
}).listen();

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

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

路径格式说明:

  • classpath:xxx - 类路径资源,从应用的类加载器中加载(推荐用于打包后的资源)
  • 直接路径 - 文件系统路径,指向服务器本地目录

使用示例:

// 类路径(默认,从 resources/static 目录加载)
options.setStaticLocations("classpath:static");
// 文件系统绝对路径
options.setStaticLocations("/var/www/static");
// 文件系统相对路径
options.setStaticLocations("./public");

功能特性:

特性说明
自动首页访问目录时自动返回 index.html
缓存支持支持 HTTP 304 缓存(基于 Last-Modified 头)
GZIP 压缩类路径资源自动启用 GZIP 压缩传输
MIME 类型自动识别常见文件类型的 Content-Type
404 处理找不到资源时返回 feat-404.html(如果存在)或 404 状态码

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();
}
}