spring-axum 0.1.0

Spring-like application framework for Axum with macro-based auto discovery, validation, transactions, caching, events, and SQL/Mapper integrations.
Documentation

spring-axum

一个基于 Axum 的“类 Spring”应用框架,提供宏驱动的自动发现(controllers/components/interceptors/advices)、验证、事务、缓存、事件、SQL/Mapper 等能力,帮助你快速搭建可维护的 Web 应用。

快速开始

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let app = spring_axum::auto_discover!();
    app.run().await
}

如需显式控制顺序:

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let app = spring_axum::SpringApp::new()
        .with_discovered_controllers()
        .with_discovered_interceptors()
        .with_discovered_advices()
        .with_discovered_components();
    app.run().await
}

主要特性

  • #[controller] / #[route] 路由与控制器
  • #[component] 组件自动注册
  • #[interceptor] 请求/响应拦截
  • #[transaction] 事务(需启用 sqlx_postgres
  • #[cacheable] 结果缓存
  • #[event] 事件发布/订阅
  • #[sql] / #[mapper] SQL 映射(MyBatis 风格)

更多示例和宏用法详见仓库顶层 README.md

功能开关

Cargo.toml 中启用所需功能:

[dependencies]
spring-axum = { version = "0.1", features = ["validator", "swagger", "sqlx_postgres"] }

许可证

MIT