Skip to content

快速开始

This content is not available in your language yet.

简笔手绘卡通风格,一个开发者把一个小小的 Java 文件放进轻量服务器,右侧浏览器窗口显示成功响应,周围有 Maven、Controller、Route 的小图标,黑色线稿,少量绿色和蓝色点缀,干净留白,技术教程插画,900x383,无复杂文字

Feat Cloud 面向这样一种场景:你已经接受 Feat Core 的轻量、高性能路线,但在业务项目里仍然希望保留 Controller、Bean、自动装配这些更熟悉的组织方式。

如果你还在评估 Feat,建议先从 Feat Core 快速开始 开始。

这章先不展开配置、数据库或部署。我们只做一件事:写出一个能被编译期识别、启动后可以访问的最小 Feat Cloud 应用。

最终效果很小:访问 http://localhost:8080/hello 返回 hello Feat Cloud
但这条链路会经过 Feat Cloud 最重要的机制:编译期扫描注解、生成服务代码、启动时注册路由。

开始前确认本地已经有 JDK 8+、Maven 3.0+ 和一个能正常运行 Maven 项目的 IDE。

pom.xml 中加入:

pom.xml
<!--运行期依赖-->
<dependency>
<groupId>tech.smartboot.feat</groupId>
<artifactId>feat-cloud</artifactId>
<version>${feat.version}</version>
</dependency>
<!--编译期生成代码-->
<dependency>
<groupId>tech.smartboot.feat</groupId>
<artifactId>feat-cloud-starter</artifactId>
<version>${feat.version}</version>
<scope>provided</scope>
</dependency>

这里有一个容易忽略的分工:feat-cloud 是运行期依赖,feat-cloud-starter 负责在编译期生成代码。
如果少了后者,应用可以编译到某一步,但 Controller 不会被转成可加载的 CloudService

创建 Bootstrap.java

Bootstrap.java
import tech.smartboot.feat.cloud.FeatCloud;
import tech.smartboot.feat.cloud.annotation.Controller;
import tech.smartboot.feat.cloud.annotation.RequestMapping;
@Controller
public class Bootstrap {
@RequestMapping("/hello")
public String helloWorld() {
return "hello Feat Cloud";
}
public static void main(String[] args) {
FeatCloud.cloudServer().listen();
}
}

这个类同时承担两个角色:

  • main 方法是应用启动入口
  • @Controller@RequestMapping 让编译器知道这里有一个 HTTP 路由

在真实项目里,你通常会把启动类和 Controller 拆开。这里合在一起,是为了让第一条链路尽量短。

运行 Bootstrap.main(),控制台出现以下内容说明路由注册成功:

控制台输出
Feat Router:
|-> /hello ==> Bootstrap@helloWorld
http://0.0.0.0:8080/

访问 http://localhost:8080/hello

Feat Cloud 浏览器访问效果图

到这里,你已经跑通了 Feat Cloud 的基本闭环。后面的章节会把这个最小应用拆开:先理解编译期生成的工作模型,再进入 Controller 请求处理、返回响应、Bean 装配、配置与环境、数据库集成和最终部署。