我已经使用 Spring Boot 和 Spring Cloud 一段时间了,使用 Spring Core 的时间更长,但我找不到关于在创建框架时使用哪种技术的明确规则:
spring.factories
文件 @EnableXxx
例如 :
spring-cloud-starter-eureka-client
并添加 @EnableEurekaClient
在一些配置类 spring-boot-starter-jdbc
在类路径上足以触发数据源自动配置。没有 @EnableDataSourceAutoConfiguration
这样的东西@EnableCaching
手动 有时
@EnableXxx
annotated class 包含在 starter 带来的代码中,有时不包含。我知道
@Enable...
是“pre Spring-Boot”方法(技术上是好看的 @Import
),但事实是 @EnableEurekaClient
存在证明它没有以任何方式被弃用。那里有什么规定?我在文档中找不到它。
最佳答案
没有硬性规定(至少从 Spring Cloud 的角度来看)。
Dave Syer说过:
A candidate rule of thumb is "if something is on the classpath but provides multiple features, you need a way to switch on a subset" I prefer to think of it as "revealing a conscious choice" as opposed to "relying on magic"
我有点像启动服务器或做工作(比如 Discovery Client)
关于spring-boot - Spring Boot spring.factories 与 @Enable 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42819558/