Phase 3:auto-exchange 已精简为基于 field-translate 的汇率转换插件。通用字段翻译、Jackson 序列化、字典翻译等能力由 field-translate 提供。
- Spring Boot 3.3.7 / Java 17
- 版本:1.0.0-SNAPSHOT
- 依赖:
field-translate-spring-boot-starter+auto-exchange-spring-boot-starter
| 模块 | 说明 |
|---|---|
auto-exchange-spring-boot-core |
汇率插件核心:ExchangeManager、ExchangeFieldTranslator 等 |
auto-exchange-spring-boot-autoconfigure |
ExchangeAutoConfiguration 自动配置 |
auto-exchange-spring-boot-starter |
聚合 starter(含 field-translate) |
auto-exchange-spring-boot-openapi |
springdoc 2.x OpenAPI 文档增强 |
auto-exchange-spring-boot-test-app |
演示与集成测试 |
auto-exchange-spring-boot-processor已移除;编译时注解校验由 field-translate 承担。
<dependency>
<groupId>io.github.juwencheng</groupId>
<artifactId>auto-exchange-spring-boot-starter</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- 字典翻译(可选) -->
<dependency>
<groupId>io.github.juwencheng</groupId>
<artifactId>field-translate-dict</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>@SpringBootApplication
@EnableFieldTranslate // 来自 field-translate
public class MyApplication { }public class Product {
@TranslateField(value = "priceInCny", translator = ExchangeFieldTranslator.class)
private BigDecimal priceUsd;
@ExchangeBaseCurrency
private String currency;
}
@GetMapping("/product")
@TranslateResponse
public Product getProduct() { ... }auto:
exchange:
refresh-on-launch: true
default-base-currency: CNY
default-target-currency: CNY
target-currency-param-name: currency
target-currency-header-name: X-Target-Currency
missing-rate:
missing-rate-strategy: return_null
translate-cache:
enabled: true
exchange-ttl: 1d
rate-refresh:
enabled: false
cron: "0 30 0 * * ?"
field:
translate:
enabled: true| 旧 API | 新 API |
|---|---|
@EnableAutoExchange |
@EnableFieldTranslate + starter |
@AutoExchangeResponse |
@TranslateResponse(field-translate) |
@AutoExchangeField |
@TranslateField(translator = ExchangeFieldTranslator.class) |
@AutoExchangeBaseCurrency |
@ExchangeBaseCurrency |
IApplyExchange 原地修改 |
移除,统一使用 Append 模式 |
IDictDataProvider(core) |
field-translate-dict 的 DictDataProvider |
DictFieldTranslator(core) |
field-translate-dict |
IExchangeDataProvider |
ExchangeDataProvider(…exchange 包) |
AutoExchangeException |
ExchangeException(…exchange.exception) |
…core.* / …provider.* / …scheduler.* |
统一到 io.github.juwencheng.autoexchange.exchange |
auto.exchange.translate-cache.dict-ttl |
移至 field.translate.dict |
auto.exchange.aspect-order |
移至 field.translate.aspect-order |
springdoc-openapi-ui 1.x |
springdoc-openapi-starter-webmvc-ui 2.6.0 |
破坏性变更:
- 移除双轨汇率(
AutoExchangeAspect、@AutoExchangeField、In-place 模式) - 移除
@EnableAutoExchange(请用@EnableFieldTranslate+ starter) - 移除
processor模块与未使用 API(如fetchData(LocalDateTime)、ExchangeProcessingException) - 包与命名收敛:
IExchangeDataProvider→ExchangeDataProvider,AutoExchangeException→ExchangeException,核心类型迁入…exchange - 需同时升级 Spring Boot 3 与 Java 17
引入 auto-exchange-spring-boot-openapi + springdoc-openapi-starter-webmvc-ui,通过 AutoConfiguration.imports 自动注册 ExchangeOperationCustomizer,为 @TranslateField(translator = ExchangeFieldTranslator.class) 字段生成 Object{base, trans, rate, price} 文档说明。
MIT License