springbootAI 1.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spring/__init__.py +66 -0
- spring/ai/__init__.py +78 -0
- spring/ai/advisors.py +139 -0
- spring/ai/annotations.py +74 -0
- spring/ai/autoconfig.py +481 -0
- spring/ai/core.py +391 -0
- spring/ai/etl.py +188 -0
- spring/ai/memory.py +109 -0
- spring/ai/observability.py +129 -0
- spring/ai/providers.py +789 -0
- spring/ai/resilience.py +258 -0
- spring/ai/tools.py +106 -0
- spring/ai/vectorstore.py +303 -0
- spring/annotations/__init__.py +188 -0
- spring/annotations/cache.py +126 -0
- spring/annotations/cloud.py +207 -0
- spring/annotations/conditional.py +272 -0
- spring/annotations/core.py +864 -0
- spring/annotations/messaging.py +107 -0
- spring/aop/__init__.py +4 -0
- spring/aop/cloud_aop.py +404 -0
- spring/aop/comprehensive_aop.py +1015 -0
- spring/aop/method_interceptor.py +19 -0
- spring/aop/proxy_factory.py +55 -0
- spring/cloud/__init__.py +76 -0
- spring/cloud/discovery.py +364 -0
- spring/cloud/feign.py +469 -0
- spring/cloud/gateway.py +452 -0
- spring/cloud/load_balancer.py +149 -0
- spring/cloud/seata.py +557 -0
- spring/cloud/sentinel.py +525 -0
- spring/cloud/tracer.py +337 -0
- spring/config/__init__.py +21 -0
- spring/config/binding.py +206 -0
- spring/config/config_loader.py +405 -0
- spring/context/__init__.py +13 -0
- spring/context/application_context.py +589 -0
- spring/context/bean_definition.py +70 -0
- spring/context/bean_factory.py +1052 -0
- spring/context/registry.py +58 -0
- spring/context/scanner.py +106 -0
- spring/core/__init__.py +3 -0
- spring/core/graceful_shutdown.py +196 -0
- spring/core/typing_utils.py +50 -0
- spring/csv/__init__.py +52 -0
- spring/csv/annotations.py +402 -0
- spring/csv/converters.py +69 -0
- spring/csv/easy_csv.py +95 -0
- spring/csv/exceptions.py +27 -0
- spring/csv/reader.py +195 -0
- spring/csv/writer.py +155 -0
- spring/data/__init__.py +54 -0
- spring/data/page.py +181 -0
- spring/data/repository.py +274 -0
- spring/data/specification.py +228 -0
- spring/datasource/__init__.py +66 -0
- spring/datasource/annotations.py +133 -0
- spring/datasource/context.py +69 -0
- spring/datasource/dynamic.py +148 -0
- spring/event/__init__.py +7 -0
- spring/event/publisher.py +69 -0
- spring/excel/__init__.py +51 -0
- spring/excel/annotations.py +405 -0
- spring/excel/converters.py +231 -0
- spring/excel/easy_excel.py +94 -0
- spring/excel/exceptions.py +31 -0
- spring/excel/reader.py +254 -0
- spring/excel/style.py +95 -0
- spring/excel/writer.py +197 -0
- spring/i18n/__init__.py +97 -0
- spring/i18n/accessor.py +94 -0
- spring/i18n/auto_config.py +177 -0
- spring/i18n/holder.py +106 -0
- spring/i18n/locale.py +152 -0
- spring/i18n/locale_resolver.py +367 -0
- spring/i18n/message_source.py +250 -0
- spring/i18n/middleware.py +79 -0
- spring/i18n/properties.py +168 -0
- spring/i18n/sources.py +255 -0
- spring/logging/__init__.py +1 -0
- spring/logging/loguru_logger.py +228 -0
- spring/main.py +378 -0
- spring/messaging/__init__.py +1 -0
- spring/messaging/rabbitmq.py +302 -0
- spring/monitoring/__init__.py +1 -0
- spring/monitoring/prometheus.py +199 -0
- spring/orm/__init__.py +258 -0
- spring/orm/database.py +222 -0
- spring/orm/ddl_auto.py +1217 -0
- spring/orm/migration.py +419 -0
- spring/orm/mybatis_integration.py +400 -0
- spring/orm/pymybatis/__init__.py +86 -0
- spring/orm/pymybatis/annotations/__init__.py +30 -0
- spring/orm/pymybatis/annotations/annotations.py +332 -0
- spring/orm/pymybatis/cache/__init__.py +47 -0
- spring/orm/pymybatis/cache/cache.py +371 -0
- spring/orm/pymybatis/cache/redis_cache.py +434 -0
- spring/orm/pymybatis/circuit_breaker/__init__.py +21 -0
- spring/orm/pymybatis/circuit_breaker/circuit_breaker.py +424 -0
- spring/orm/pymybatis/configuration.py +525 -0
- spring/orm/pymybatis/core/__init__.py +10 -0
- spring/orm/pymybatis/core/sql_session.py +1382 -0
- spring/orm/pymybatis/core/sql_session_factory.py +76 -0
- spring/orm/pymybatis/dialect/__init__.py +9 -0
- spring/orm/pymybatis/dialect/dialect.py +445 -0
- spring/orm/pymybatis/dynamic_sql/__init__.py +9 -0
- spring/orm/pymybatis/dynamic_sql/dynamic_sql.py +900 -0
- spring/orm/pymybatis/interceptor/__init__.py +31 -0
- spring/orm/pymybatis/interceptor/interceptor.py +427 -0
- spring/orm/pymybatis/mapper/__init__.py +9 -0
- spring/orm/pymybatis/mapper/mapper.py +540 -0
- spring/orm/pymybatis/metrics/__init__.py +41 -0
- spring/orm/pymybatis/metrics/metrics.py +595 -0
- spring/orm/pymybatis/pool/__init__.py +9 -0
- spring/orm/pymybatis/pool/connection_pool.py +711 -0
- spring/orm/pymybatis/security/__init__.py +19 -0
- spring/orm/pymybatis/security/access_control.py +415 -0
- spring/orm/pymybatis/security/password_encoder.py +293 -0
- spring/orm/pymybatis/security/sensitive_data_masker.py +326 -0
- spring/orm/pymybatis/security/sql_injection_detector.py +675 -0
- spring/orm/pymybatis/transaction/__init__.py +9 -0
- spring/orm/pymybatis/transaction/transaction.py +288 -0
- spring/orm/pymybatis/type_handler/__init__.py +37 -0
- spring/orm/pymybatis/type_handler/type_handler.py +473 -0
- spring/orm/pymybatis/version.py +9 -0
- spring/orm/pymybatis/xml_parser/__init__.py +9 -0
- spring/orm/pymybatis/xml_parser/xml_parser.py +761 -0
- spring/retry/__init__.py +12 -0
- spring/retry/retry_annotations.py +71 -0
- spring/retry/retry_decorator.py +155 -0
- spring/scheduling/__init__.py +3 -0
- spring/scheduling/scheduler.py +389 -0
- spring/security/__init__.py +39 -0
- spring/security/jwt_utils.py +281 -0
- spring/security/replay_protection.py +206 -0
- spring/security/secret_manager.py +226 -0
- spring/security/security_aop.py +248 -0
- spring/security/security_context.py +172 -0
- spring/test/__init__.py +45 -0
- spring/test/slicing.py +341 -0
- spring/tracing/__init__.py +11 -0
- spring/tracing/skywalking.py +229 -0
- spring/tx/__init__.py +52 -0
- spring/tx/events.py +172 -0
- spring/tx/synchronization.py +143 -0
- spring/utils/__init__.py +5 -0
- spring/utils/banner.py +32 -0
- spring/utils/logger.py +73 -0
- spring/utils/redis_client.py +526 -0
- spring/validation/__init__.py +55 -0
- spring/validation/aop.py +141 -0
- spring/validation/constraints.py +357 -0
- spring/validation/exceptions.py +55 -0
- spring/validation/validator.py +139 -0
- spring/web/__init__.py +12 -0
- spring/web/actuator.py +319 -0
- spring/web/exception_handler.py +61 -0
- spring/web/health.py +399 -0
- spring/web/interceptor.py +91 -0
- spring/web/result.py +44 -0
- spring/web/swagger.py +601 -0
- spring/web/web_context.py +755 -0
- spring/websocket/__init__.py +86 -0
- spring/websocket/annotations.py +169 -0
- spring/websocket/broker.py +238 -0
- spring/websocket/exceptions.py +26 -0
- spring/websocket/handler.py +243 -0
- spring/websocket/router.py +526 -0
- spring/websocket/session.py +216 -0
- springbootai-1.8.0.dist-info/METADATA +2796 -0
- springbootai-1.8.0.dist-info/RECORD +175 -0
- springbootai-1.8.0.dist-info/WHEEL +5 -0
- springbootai-1.8.0.dist-info/entry_points.txt +2 -0
- springbootai-1.8.0.dist-info/licenses/LICENSE +7 -0
- springbootai-1.8.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
from .core import (
|
|
2
|
+
SpringBootApplication,
|
|
3
|
+
ComponentScan,
|
|
4
|
+
ApplicationEvent,
|
|
5
|
+
EventListener,
|
|
6
|
+
RestController,
|
|
7
|
+
Controller,
|
|
8
|
+
RequestMapping,
|
|
9
|
+
GetMapping,
|
|
10
|
+
PostMapping,
|
|
11
|
+
PutMapping,
|
|
12
|
+
PatchMapping,
|
|
13
|
+
DeleteMapping,
|
|
14
|
+
Service,
|
|
15
|
+
Component,
|
|
16
|
+
Repository,
|
|
17
|
+
Autowired,
|
|
18
|
+
Qualifier,
|
|
19
|
+
Configuration,
|
|
20
|
+
Scope,
|
|
21
|
+
Bean,
|
|
22
|
+
Value,
|
|
23
|
+
ConfigurationProperties,
|
|
24
|
+
RequestParam,
|
|
25
|
+
PathVariable,
|
|
26
|
+
RequestBody,
|
|
27
|
+
Valid,
|
|
28
|
+
Validated,
|
|
29
|
+
CrossOrigin,
|
|
30
|
+
ControllerAdvice,
|
|
31
|
+
ExceptionHandler,
|
|
32
|
+
Slf4j,
|
|
33
|
+
LogExecutionTime,
|
|
34
|
+
PostConstruct,
|
|
35
|
+
PreDestroy,
|
|
36
|
+
Primary,
|
|
37
|
+
Profile,
|
|
38
|
+
Lazy,
|
|
39
|
+
RequestHeader,
|
|
40
|
+
CookieValue,
|
|
41
|
+
ResponseStatus,
|
|
42
|
+
Transactional,
|
|
43
|
+
Cacheable,
|
|
44
|
+
Retryable,
|
|
45
|
+
Async,
|
|
46
|
+
Scheduled,
|
|
47
|
+
AsyncResult,
|
|
48
|
+
RateLimit,
|
|
49
|
+
CircuitBreaker,
|
|
50
|
+
Idempotent,
|
|
51
|
+
AuditLog,
|
|
52
|
+
FeatureToggle,
|
|
53
|
+
Lock,
|
|
54
|
+
Metrics,
|
|
55
|
+
Synchronized,
|
|
56
|
+
Validate,
|
|
57
|
+
Trace,
|
|
58
|
+
PreAuthorize,
|
|
59
|
+
Secured,
|
|
60
|
+
Authenticate,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
from .cloud import (
|
|
64
|
+
EnableDiscoveryClient,
|
|
65
|
+
NacosValue,
|
|
66
|
+
RefreshScope,
|
|
67
|
+
EnableFeignClients,
|
|
68
|
+
FeignClient,
|
|
69
|
+
SentinelResource,
|
|
70
|
+
EnableGateway,
|
|
71
|
+
LoadBalanced,
|
|
72
|
+
GlobalTransactional,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# 缓存增强注解(@CachePut / @CacheEvict / @CacheConfig / @Caching),对齐 Spring Cache
|
|
76
|
+
from .cache import (
|
|
77
|
+
CachePut,
|
|
78
|
+
CacheEvict,
|
|
79
|
+
CacheConfig,
|
|
80
|
+
Caching,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# 条件装配注解(@Conditional / @ConditionalOnProperty / ...),对齐 Spring Boot
|
|
84
|
+
from .conditional import (
|
|
85
|
+
Conditional,
|
|
86
|
+
ConditionalOnProperty,
|
|
87
|
+
ConditionalOnBean,
|
|
88
|
+
ConditionalOnMissingBean,
|
|
89
|
+
ConditionalOnClass,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# 可选导入:消息队列注解(需要pika)
|
|
93
|
+
try:
|
|
94
|
+
from .messaging import (
|
|
95
|
+
RabbitListener,
|
|
96
|
+
RabbitTemplate,
|
|
97
|
+
)
|
|
98
|
+
except ImportError:
|
|
99
|
+
# pika未安装,这些注解不可用
|
|
100
|
+
RabbitListener = None
|
|
101
|
+
RabbitTemplate = None
|
|
102
|
+
|
|
103
|
+
__all__ = [
|
|
104
|
+
"SpringBootApplication",
|
|
105
|
+
"ComponentScan",
|
|
106
|
+
"ApplicationEvent",
|
|
107
|
+
"EventListener",
|
|
108
|
+
"RestController",
|
|
109
|
+
"Controller",
|
|
110
|
+
"RequestMapping",
|
|
111
|
+
"GetMapping",
|
|
112
|
+
"PostMapping",
|
|
113
|
+
"PutMapping",
|
|
114
|
+
"PatchMapping",
|
|
115
|
+
"DeleteMapping",
|
|
116
|
+
"Service",
|
|
117
|
+
"Component",
|
|
118
|
+
"Repository",
|
|
119
|
+
"Autowired",
|
|
120
|
+
"Qualifier",
|
|
121
|
+
"Configuration",
|
|
122
|
+
"Scope",
|
|
123
|
+
"Bean",
|
|
124
|
+
"Value",
|
|
125
|
+
"ConfigurationProperties",
|
|
126
|
+
"RequestParam",
|
|
127
|
+
"PathVariable",
|
|
128
|
+
"RequestBody",
|
|
129
|
+
"CrossOrigin",
|
|
130
|
+
"ControllerAdvice",
|
|
131
|
+
"ExceptionHandler",
|
|
132
|
+
"Slf4j",
|
|
133
|
+
"LogExecutionTime",
|
|
134
|
+
"PostConstruct",
|
|
135
|
+
"PreDestroy",
|
|
136
|
+
"Primary",
|
|
137
|
+
"Profile",
|
|
138
|
+
"Lazy",
|
|
139
|
+
"RequestHeader",
|
|
140
|
+
"CookieValue",
|
|
141
|
+
"ResponseStatus",
|
|
142
|
+
"Transactional",
|
|
143
|
+
"Cacheable",
|
|
144
|
+
"Retryable",
|
|
145
|
+
"Async",
|
|
146
|
+
"Scheduled",
|
|
147
|
+
"AsyncResult",
|
|
148
|
+
"RateLimit",
|
|
149
|
+
"CircuitBreaker",
|
|
150
|
+
"Idempotent",
|
|
151
|
+
"AuditLog",
|
|
152
|
+
"FeatureToggle",
|
|
153
|
+
"Lock",
|
|
154
|
+
"Metrics",
|
|
155
|
+
"Synchronized",
|
|
156
|
+
"Validate",
|
|
157
|
+
"Trace",
|
|
158
|
+
# 安全注解
|
|
159
|
+
"PreAuthorize",
|
|
160
|
+
"Secured",
|
|
161
|
+
"Authenticate",
|
|
162
|
+
# Spring Cloud 注解
|
|
163
|
+
"EnableDiscoveryClient",
|
|
164
|
+
"NacosValue",
|
|
165
|
+
"RefreshScope",
|
|
166
|
+
"EnableFeignClients",
|
|
167
|
+
"FeignClient",
|
|
168
|
+
"SentinelResource",
|
|
169
|
+
"EnableGateway",
|
|
170
|
+
"LoadBalanced",
|
|
171
|
+
"GlobalTransactional",
|
|
172
|
+
"Valid",
|
|
173
|
+
"Validated",
|
|
174
|
+
# 缓存增强注解
|
|
175
|
+
"CachePut",
|
|
176
|
+
"CacheEvict",
|
|
177
|
+
"CacheConfig",
|
|
178
|
+
"Caching",
|
|
179
|
+
# 条件装配注解
|
|
180
|
+
"Conditional",
|
|
181
|
+
"ConditionalOnProperty",
|
|
182
|
+
"ConditionalOnBean",
|
|
183
|
+
"ConditionalOnMissingBean",
|
|
184
|
+
"ConditionalOnClass",
|
|
185
|
+
# 消息队列注解
|
|
186
|
+
"RabbitListener",
|
|
187
|
+
"RabbitTemplate",
|
|
188
|
+
]
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""SpringBootAI 缓存增强注解 —— 对齐 Spring Cache 抽象的完整操作族。
|
|
2
|
+
|
|
3
|
+
本模块在既有 ``@Cacheable``(``spring.annotations.core.Cacheable``)基础上补齐 Spring Cache
|
|
4
|
+
剩余四个核心注解,复用同一 ``SpringAnnotation`` 元数据范式:
|
|
5
|
+
|
|
6
|
+
- ``@CachePut``:方法**总是执行**,把返回值写入缓存(更新缓存)。
|
|
7
|
+
- ``@CacheEvict``:方法执行后(或前)失效缓存(按 key 或 all_entries)。
|
|
8
|
+
- ``@CacheConfig``:类级注解,为类内方法提供默认 cache name / key 生成器。
|
|
9
|
+
- ``@Caching``:组合多个缓存操作(cacheable/put/evict)。
|
|
10
|
+
|
|
11
|
+
与 Spring 的一致点:
|
|
12
|
+
- 操作语义(put/evict/condition/all_entries/before_invocation)对齐 Spring Cache。
|
|
13
|
+
- ``@CacheConfig`` 作为类级默认值,方法注解显式指定时覆盖。
|
|
14
|
+
|
|
15
|
+
与 Spring 的差异(已标注):
|
|
16
|
+
- Spring 的 ``@CacheConfig``/``@Caching`` 依赖 ``CacheManager`` + ``KeyGenerator`` 抽象;
|
|
17
|
+
本框架复用 ``BeanFactory`` 内置的进程内缓存(``_cache`` / ``_cache_metadata``,与
|
|
18
|
+
``@Cacheable`` 同一存储),由 ``bean_factory._apply_aop_proxy`` 统一包装切面。
|
|
19
|
+
- ``condition`` 仅支持参数名(或 ``!参数名`` 取反)与 callable,不支持 SpEL 表达式
|
|
20
|
+
(与既有 ``@Cacheable.condition`` 保持一致,避免引入 SpEL 引擎)。
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from typing import Any, List, Optional, Tuple, Type, Union
|
|
25
|
+
|
|
26
|
+
from spring.annotations.core import SpringAnnotation
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CachePut(SpringAnnotation):
|
|
30
|
+
"""``@CachePut``:方法总是执行,把返回值写入缓存(对齐 Spring ``@CachePut``)。
|
|
31
|
+
|
|
32
|
+
与 ``@Cacheable`` 的区别:``@Cacheable`` 命中缓存时跳过方法;``@CachePut`` **总是**
|
|
33
|
+
执行方法并把结果写入缓存(用于强制刷新缓存)。
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
value: 缓存名(命名空间)。为空时回退到类级 ``@CacheConfig`` 默认。
|
|
37
|
+
key: 缓存 key。支持 ``{param}`` 模板或纯参数名;为空时按全部参数聚合。
|
|
38
|
+
condition: 条件表达式。仅当为真时才写入。支持参数名/``!参数名``/callable。
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
_annotation_type = "aop"
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
value: str = "",
|
|
46
|
+
key: Optional[str] = None,
|
|
47
|
+
condition: Optional[Union[str, Any]] = None,
|
|
48
|
+
):
|
|
49
|
+
super().__init__(value=value, key=key, condition=condition)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class CacheEvict(SpringAnnotation):
|
|
53
|
+
"""``@CacheEvict``:失效缓存(对齐 Spring ``@CacheEvict``)。
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
value: 缓存名(命名空间)。为空时回退到类级 ``@CacheConfig`` 默认。
|
|
57
|
+
key: 缓存 key。支持 ``{param}`` 模板或纯参数名;为空且
|
|
58
|
+
``all_entries=False`` 时按全部参数聚合。
|
|
59
|
+
condition: 条件表达式。仅当为真时才失效。
|
|
60
|
+
all_entries: 是否清空整个缓存命名空间(所有 ``value:*`` 条目)。默认 False。
|
|
61
|
+
before_invocation: 是否在方法**调用前**失效(默认 False=调用成功后失效)。
|
|
62
|
+
调用前失效无论方法成功与否都执行;调用后失效仅在方法成功时执行。
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
_annotation_type = "aop"
|
|
66
|
+
|
|
67
|
+
def __init__(
|
|
68
|
+
self,
|
|
69
|
+
value: str = "",
|
|
70
|
+
key: Optional[str] = None,
|
|
71
|
+
condition: Optional[Union[str, Any]] = None,
|
|
72
|
+
all_entries: bool = False,
|
|
73
|
+
before_invocation: bool = False,
|
|
74
|
+
):
|
|
75
|
+
super().__init__(
|
|
76
|
+
value=value, key=key, condition=condition,
|
|
77
|
+
all_entries=all_entries, before_invocation=before_invocation,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class CacheConfig(SpringAnnotation):
|
|
82
|
+
"""``@CacheConfig``:类级缓存配置,为类内方法提供默认值(对齐 Spring ``@CacheConfig``)。
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
cache_names: 默认缓存名列表(方法注解未指定 ``value`` 时取第一个)。
|
|
86
|
+
key_generator: key 生成器名(保留字段,当前未实现自定义生成器,仅元数据)。
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
_annotation_type = "aop"
|
|
90
|
+
|
|
91
|
+
def __init__(
|
|
92
|
+
self,
|
|
93
|
+
cache_names: Optional[List[str]] = None,
|
|
94
|
+
key_generator: Optional[str] = None,
|
|
95
|
+
):
|
|
96
|
+
super().__init__(
|
|
97
|
+
cache_names=list(cache_names) if cache_names else [],
|
|
98
|
+
key_generator=key_generator,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class Caching(SpringAnnotation):
|
|
103
|
+
"""``@Caching``:组合多个缓存操作(对齐 Spring ``@Caching``)。
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
cacheable: 组合的 ``@Cacheable`` 操作列表。
|
|
107
|
+
put: 组合的 ``@CachePut`` 操作列表。
|
|
108
|
+
evict: 组合的 ``@CacheEvict`` 操作列表。
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
_annotation_type = "aop"
|
|
112
|
+
|
|
113
|
+
def __init__(
|
|
114
|
+
self,
|
|
115
|
+
cacheable: Optional[List[Any]] = None,
|
|
116
|
+
put: Optional[List[Any]] = None,
|
|
117
|
+
evict: Optional[List[Any]] = None,
|
|
118
|
+
):
|
|
119
|
+
super().__init__(
|
|
120
|
+
cacheable=list(cacheable) if cacheable else [],
|
|
121
|
+
put=list(put) if put else [],
|
|
122
|
+
evict=list(evict) if evict else [],
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
__all__ = ["CachePut", "CacheEvict", "CacheConfig", "Caching"]
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Spring Cloud 微服务注解
|
|
3
|
+
包含注册发现、配置中心、Feign、熔断限流、网关、负载均衡、分布式事务等注解
|
|
4
|
+
"""
|
|
5
|
+
from typing import Optional, Union, Dict, Any, Type, List, Callable
|
|
6
|
+
from .core import SpringAnnotation, Valid, Validated
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# ==================== 注册发现注解 ====================
|
|
10
|
+
|
|
11
|
+
class EnableDiscoveryClient(SpringAnnotation):
|
|
12
|
+
"""
|
|
13
|
+
启用服务注册发现
|
|
14
|
+
所有微服务(服务提供者、消费者、网关)都要加
|
|
15
|
+
通用兼容:SpringCloud新版本统一使用该注解,不要混用@EnableEurekaClient
|
|
16
|
+
|
|
17
|
+
使用注意:
|
|
18
|
+
- 必须在application.yml配置spring.application.name,否则注册中心显示未知服务
|
|
19
|
+
- Feign调用依赖服务名配置
|
|
20
|
+
"""
|
|
21
|
+
_annotation_type = "discovery"
|
|
22
|
+
|
|
23
|
+
def __init__(self, client_type: str = "nacos"):
|
|
24
|
+
super().__init__(client_type=client_type)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class NacosValue(SpringAnnotation):
|
|
28
|
+
"""
|
|
29
|
+
Nacos配置动态刷新注解
|
|
30
|
+
和@Value区别:@Value配置变更不会自动刷新,@NacosValue(autoRefreshed=True)才支持动态刷新
|
|
31
|
+
|
|
32
|
+
使用注意:
|
|
33
|
+
- 基础类型生效,复杂实体类不推荐
|
|
34
|
+
- 批量配置绑定优先使用@ConfigurationProperties
|
|
35
|
+
"""
|
|
36
|
+
_annotation_type = "value"
|
|
37
|
+
|
|
38
|
+
def __init__(self, value: str, auto_refreshed: bool = False):
|
|
39
|
+
super().__init__(value=value, auto_refreshed=auto_refreshed)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# ==================== 配置中心注解 ====================
|
|
43
|
+
|
|
44
|
+
class RefreshScope(SpringAnnotation):
|
|
45
|
+
"""
|
|
46
|
+
配置刷新作用域注解
|
|
47
|
+
仅加了该注解的类,配置变更才会自动刷新
|
|
48
|
+
|
|
49
|
+
使用注意:
|
|
50
|
+
- 不能标注在@Controller上,会导致接口上下文丢失、请求参数解析异常
|
|
51
|
+
- 动态配置读取放在Service层
|
|
52
|
+
- 会创建代理类,存在循环依赖的Bean会启动直接报错
|
|
53
|
+
"""
|
|
54
|
+
_annotation_type = "refresh_scope"
|
|
55
|
+
|
|
56
|
+
def __init__(self):
|
|
57
|
+
super().__init__()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# ==================== Feign远程调用注解 ====================
|
|
61
|
+
|
|
62
|
+
class EnableFeignClients(SpringAnnotation):
|
|
63
|
+
"""
|
|
64
|
+
启用Feign客户端扫描
|
|
65
|
+
默认只扫描启动类同包下的Feign接口
|
|
66
|
+
|
|
67
|
+
使用注意:
|
|
68
|
+
- Feign接口放在其他包时,必须指定扫描路径
|
|
69
|
+
- 不能和Dubbo注解混用,会出现RPC上下文冲突
|
|
70
|
+
"""
|
|
71
|
+
_annotation_type = "feign"
|
|
72
|
+
|
|
73
|
+
def __init__(self, base_packages: Optional[List[str]] = None):
|
|
74
|
+
super().__init__(base_packages=base_packages)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class FeignClient(SpringAnnotation):
|
|
78
|
+
"""
|
|
79
|
+
Feign客户端注解
|
|
80
|
+
value值必须和目标服务spring.application.name完全一致,大小写敏感
|
|
81
|
+
|
|
82
|
+
使用注意:
|
|
83
|
+
- fallback降级类必须实现当前Feign接口,且交给Spring管理
|
|
84
|
+
- 如果目标服务配置server.servlet.context-path,必须通过path属性指定
|
|
85
|
+
- 禁止在Feign接口方法上使用@Valid做参数校验
|
|
86
|
+
"""
|
|
87
|
+
_annotation_type = "feign"
|
|
88
|
+
|
|
89
|
+
def __init__(
|
|
90
|
+
self,
|
|
91
|
+
value: str,
|
|
92
|
+
path: str = "",
|
|
93
|
+
fallback: Optional[Type] = None,
|
|
94
|
+
fallback_factory: Optional[Type] = None,
|
|
95
|
+
url: str = "",
|
|
96
|
+
):
|
|
97
|
+
super().__init__(
|
|
98
|
+
value=value,
|
|
99
|
+
path=path,
|
|
100
|
+
fallback=fallback,
|
|
101
|
+
fallback_factory=fallback_factory,
|
|
102
|
+
url=url,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# ==================== 熔断限流注解 ====================
|
|
107
|
+
|
|
108
|
+
class SentinelResource(SpringAnnotation):
|
|
109
|
+
"""
|
|
110
|
+
Sentinel资源保护注解(Alibaba Sentinel,生产推荐)
|
|
111
|
+
value资源名唯一,建议和接口路径保持一致
|
|
112
|
+
|
|
113
|
+
使用注意:
|
|
114
|
+
- blockHandler:只处理限流、黑名单、系统保护这类Sentinel阻断异常
|
|
115
|
+
- fallback:处理业务异常、远程调用异常,二者分工不同
|
|
116
|
+
- 限流/降级处理函数:返回值、参数列表必须和原接口完全一致
|
|
117
|
+
- 热点参数限流:需要指定hotkey="参数名",基础类型参数才生效
|
|
118
|
+
"""
|
|
119
|
+
_annotation_type = "aop"
|
|
120
|
+
|
|
121
|
+
def __init__(
|
|
122
|
+
self,
|
|
123
|
+
value: str,
|
|
124
|
+
block_handler: str = "",
|
|
125
|
+
fallback: str = "",
|
|
126
|
+
block_handler_class: Optional[Type] = None,
|
|
127
|
+
fallback_class: Optional[Type] = None,
|
|
128
|
+
hotkey: str = "",
|
|
129
|
+
exceptions_to_ignore: Optional[List[Type[Exception]]] = None,
|
|
130
|
+
):
|
|
131
|
+
super().__init__(
|
|
132
|
+
value=value,
|
|
133
|
+
block_handler=block_handler,
|
|
134
|
+
fallback=fallback,
|
|
135
|
+
block_handler_class=block_handler_class,
|
|
136
|
+
fallback_class=fallback_class,
|
|
137
|
+
hotkey=hotkey,
|
|
138
|
+
exceptions_to_ignore=exceptions_to_ignore or [],
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# ==================== 网关注解 ====================
|
|
143
|
+
|
|
144
|
+
class EnableGateway(SpringAnnotation):
|
|
145
|
+
"""
|
|
146
|
+
启用Gateway网关
|
|
147
|
+
仅网关模块启动类添加,业务服务禁止引入Gateway依赖和该注解
|
|
148
|
+
|
|
149
|
+
使用注意:
|
|
150
|
+
- 会引入WebFlux依赖,和SpringMVC冲突
|
|
151
|
+
- 不能使用SpringMVC的拦截器,自定义逻辑必须使用Gateway全局过滤器GlobalFilter
|
|
152
|
+
"""
|
|
153
|
+
_annotation_type = "gateway"
|
|
154
|
+
|
|
155
|
+
def __init__(self):
|
|
156
|
+
super().__init__()
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# ==================== 负载均衡注解 ====================
|
|
160
|
+
|
|
161
|
+
class LoadBalanced(SpringAnnotation):
|
|
162
|
+
"""
|
|
163
|
+
负载均衡注解
|
|
164
|
+
仅作用于@Bean修饰的RestTemplate
|
|
165
|
+
|
|
166
|
+
使用注意:
|
|
167
|
+
- 不能标注在注入字段、类上,仅能放在创建RestTemplate的Bean方法上
|
|
168
|
+
- WebClient负载均衡需单独配置,该注解不生效
|
|
169
|
+
"""
|
|
170
|
+
_annotation_type = "bean"
|
|
171
|
+
|
|
172
|
+
def __init__(self, strategy: str = "round_robin"):
|
|
173
|
+
super().__init__()
|
|
174
|
+
self.strategy = strategy
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# ==================== 分布式事务注解 ====================
|
|
178
|
+
|
|
179
|
+
class GlobalTransactional(SpringAnnotation):
|
|
180
|
+
"""
|
|
181
|
+
Seata分布式事务注解
|
|
182
|
+
仅事务发起入口方法添加,所有参与分布式事务的微服务不需要添加该注解
|
|
183
|
+
|
|
184
|
+
使用注意:
|
|
185
|
+
- 数据库必须使用InnoDB引擎,支持行锁
|
|
186
|
+
- 业务表必须存在主键
|
|
187
|
+
- 必须配置Seata注册中心、事务组
|
|
188
|
+
- 不支持嵌套事务
|
|
189
|
+
- 只有RuntimeException才会触发全局回滚
|
|
190
|
+
- 禁止在异步线程中使用,事务上下文无法传递
|
|
191
|
+
"""
|
|
192
|
+
_annotation_type = "aop"
|
|
193
|
+
|
|
194
|
+
def __init__(
|
|
195
|
+
self,
|
|
196
|
+
timeout: int = 60000,
|
|
197
|
+
name: str = "",
|
|
198
|
+
rollback_for: Optional[List[Type[Exception]]] = None,
|
|
199
|
+
no_rollback_for: Optional[List[Type[Exception]]] = None,
|
|
200
|
+
):
|
|
201
|
+
super().__init__(
|
|
202
|
+
timeout=timeout,
|
|
203
|
+
name=name,
|
|
204
|
+
rollback_for=rollback_for or [],
|
|
205
|
+
no_rollback_for=no_rollback_for or [],
|
|
206
|
+
)
|
|
207
|
+
|