我将我的项目从 spring-boot 2.1.9 移动到 2.2.0。
在启动项目时,我面临以下
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'linkDiscoverers' defined in class path resource [org/springframework/hateoas/config/HateoasConfiguration.class]: Unsatisfied dependency expressed through method 'linkDiscoverers' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.plugin.core.PluginRegistry<org.springframework.hateoas.client.LinkDiscoverer, org.springframework.http.MediaType>' available: expected single matching bean but found 17: modelBuilderPluginRegistry,modelPropertyBuilderPluginRegistry,typeNameProviderPluginRegistry,syntheticModelProviderPluginRegistry,documentationPluginRegistry,apiListingBuilderPluginRegistry,operationBuilderPluginRegistry,parameterBuilderPluginRegistry,expandedParameterBuilderPluginRegistry,resourceGroupingStrategyRegistry,operationModelsProviderPluginRegistry,defaultsProviderPluginRegistry,pathDecoratorRegistry,apiListingScannerPluginRegistry,relProviderPluginRegistry,linkDiscovererRegistry,entityLinksPluginRegistry *************************** APPLICATION FAILED TO START *************************** Description: Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration required a single bean, but 17 were found: - modelBuilderPluginRegistry: defined in null - modelPropertyBuilderPluginRegistry: defined in null - typeNameProviderPluginRegistry: defined in null - syntheticModelProviderPluginRegistry: defined in null - documentationPluginRegistry: defined in null - apiListingBuilderPluginRegistry: defined in null - operationBuilderPluginRegistry: defined in null - parameterBuilderPluginRegistry: defined in null - expandedParameterBuilderPluginRegistry: defined in null - resourceGroupingStrategyRegistry: defined in null - operationModelsProviderPluginRegistry: defined in null - defaultsProviderPluginRegistry: defined in null - pathDecoratorRegistry: defined in null - apiListingScannerPluginRegistry: defined in null - relProviderPluginRegistry: defined by method 'relProviderPluginRegistry' in class path resource [org/springframework/hateoas/config/HateoasConfiguration.class] - linkDiscovererRegistry: defined in null - entityLinksPluginRegistry: defined by method 'entityLinksPluginRegistry' in class path resource [org/springframework/hateoas/config/WebMvcEntityLinksConfiguration.class] |
是什么导致了这个问题?
注意:我没有在我的
pom.xml
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | <java.version>1.8</java.version> <swagger-springfox.version>2.9.2</swagger-springfox.version> <sonar.jacoco.execPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.execPath> <jasypt-spring-boot-starter>2.1.1</jasypt-spring-boot-starter> <logbook-spring-boot-starter>1.13.0</logbook-spring-boot-starter> 0.8.1</assertj-swagger> <jacoco-version>0.8.4</jacoco-version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> spring-boot-starter-data-rest</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> spring-boot-configuration-processor</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger2</artifactId> <version>${swagger-springfox.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger-ui</artifactId> <version>${swagger-springfox.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-spring-web</artifactId> <version>${swagger-springfox.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-core</artifactId> <version>${swagger-springfox.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-data-rest</artifactId> <version>${swagger-springfox.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-bean-validators</artifactId> <version>${swagger-springfox.version}</version> </dependency> |
我的
下面给出了修复(编辑你的 Swagger 配置类):
2 3 4 5 6 7 8 9 10 11 12 | @EnableSwagger2 public class SwaggerConfiguration { @Bean public LinkDiscoverers discoverers() { List<LinkDiscoverer> plugins = new ArrayList<>(); plugins.add(new CollectionJsonLinkDiscoverer()); return new LinkDiscoverers(SimplePluginRegistry.create(plugins)); } } |
对我来说这个链接有帮助:https://github.com/spring-projects/spring-hateoas/issues/731
简而言之,我添加了我的依赖项:
2 3 4 5 | <groupId>org.springframework.plugin</groupId> spring-plugin-core</artifactId> <version>2.0.0.RELEASE</version> </dependency> |
此类问题是由于 Hateoas 的一项新功能而发生的。
如果你想解决这个问题,只需在你的swagger配置文件中嵌入下面这行代码即可。
2 3 4 5 6 7 | @Bean public LinkDiscoverers discoverers() { List<LinkDiscoverer> plugins = new ArrayList<>(); plugins.add(new CollectionJsonLinkDiscoverer()); return new LinkDiscoverers(SimplePluginRegistry.create(plugins)); } |
我认为这会解决你的问题,因为它解决了我的问题。
2 3 4 5 6 7 8 9 10 11 12 13 14 15 | If Spring Boot version is >= 2.2.0 the use io.springfox version 3.0.0 <dependency> <groupId>io.springfox</groupId> springfox-swagger2</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger-ui</artifactId> <version>3.0.0</version> </dependency> |
使用 3.0.0 版本后,swagger-ui 将无法工作,因此请使用以下依赖项和用户 /swagger-ui/ 而不是 /swagger-ui.html
2 3 4 5 | <groupId>io.springfox</groupId> springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> |
我使用
时遇到的问题
2 3 4 5 6 7 8 9 10 11 12 13 | <groupId>org.springframework.boot</groupId> spring-boot-dependencies</artifactId> <version>2.2.6.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> ..... ..... <dependency> <groupId>org.springframework.boot</groupId> spring-boot-starter-hateoas</artifactId> </dependency> |
用springfox招摇
2 3 4 5 6 7 8 9 10 | <groupId>io.springfox</groupId> springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> |
如果您查看 spring hateoas 依赖项,则存在对
的依赖项
2 3 4 5 | <groupId>org.springframework.plugin</groupId> spring-plugin-core</artifactId> <version>${spring-plugin.version}</version> </dependency> |
但是大张旗鼓的依赖使用
spring-boot创建bean有冲突,需要统一
所以版本
2 3 4 5 | <groupId>org.springframework.plugin</groupId> spring-plugin-core</artifactId> <version>1.2.0.RELEASE</version> </dependency> |
之后,您需要配置类来为
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | @Configuration public class SwaggerConfiguration { @Primary @Bean public LinkDiscoverers discoverers() { List<LinkDiscoverer> plugins = new ArrayList<>(); plugins.add(new CollectionJsonLinkDiscoverer()); return new LinkDiscoverers(SimplePluginRegistry.create(plugins)); } @Bean public Docket postsApi() { return new Docket(DocumentationType.SWAGGER_2) .groupName("{ApplicationName}") .apiInfo(buildApiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.regex("/.*")) .build(); } private ApiInfo buildApiInfo() { Contact contact = new Contact("CompanyName","https://company-domain.com","mail@company.com"); return new ApiInfoBuilder() .title(""{ApplicationName}"") .description("API Description") .license("license") .version("1.0") .contact(contact) .licenseUrl("licenseURl") .build(); } } |
对于 Spring boot 版本
2 3 4 5 6 7 8 9 10 11 12 13 14 | <groupId>org.springframework.boot</groupId> spring-boot-starter-hateoas</artifactId> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> |
试试这个2.6.1版本,我已经用这个方法解决了
2 3 4 5 6 7 8 9 10 | <groupId>io.springfox</groupId> springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> |
我正在使用 springdoc-openapi,在遇到类似于这里提到的问题后:
2 3 4 5 6 7 8 9 10 11 | Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration required a single bean, but 3 were found: - relProviderPluginRegistry: defined by method 'relProviderPluginRegistry' in class path resource [org/springframework/hateoas/config/HateoasConfiguration.class] - linkDiscovererRegistry: defined in null - entityLinksPluginRegistry: defined by method 'entityLinksPluginRegistry' in class path resource [org/springframework/hateoas/config/WebMvcEntityLinksConfiguration.class] Action: Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed |
我只是在我的 pom 文件中添加了这个依赖
2 3 4 5 | <groupId>org.springframework.hateoas</groupId> spring-hateoas</artifactId> <version>1.1.1.RELEASE</version> </dependency> |
希望这可以帮助某人
最佳解决方案
在 SwaggerConfig 类中添加以下代码
2 3 4 5 6 | public LinkDiscoverers discovers() { List<LinkDiscoverer> plugins = new ArrayList<>(); plugins.add(new CollectionJsonLinkDiscoverer()); return new LinkDiscoverers(SimplePluginRegistry.create(plugins));[enter image description here][1] } |
作为亚历山大·魏?已经回答,
为了强制使用正确的
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <spring-plugin-core.version>2.0.0.RELEASE</spring-plugin-core.version> <springfox.version>3.0.0</springfox.version> </properties> <dependencyManagement> <dependencies> <!-- API Documentation --> <!-- Fix wrong resolved `spring-plugin-core` dependency version for springfox --> <dependency> <groupId>org.springframework.plugin</groupId> spring-plugin-core</artifactId> <version>${spring-plugin-core.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-boot-starter</artifactId> <version>${springfox.version}</version> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- API Documentation --> <dependency> <groupId>io.springfox</groupId> springfox-boot-starter</artifactId> </dependency> </dependencies> |
我收到错误
"在类路径资源 [org/springframework/hateoas/mediatype/hal/HalMediaTypeConfiguration.class] 中定义名称为 'halLinkDisocoverer' 的 bean 创建错误"..
在构建超媒体驱动的 RESTful Web 服务时
删除这个依赖
2 3 4 5 | <groupId>com.jayway.jsonpath</groupId> json-path</artifactId> <scope>test</scope> </dependency> |
解决了我的问题。
查看此链接了解更多详情
为什么我收到错误工厂方法"halLinkDisocoverer"在 springboot 中引发异常?
您可以像这样更改版本:
2 3 4 5 6 7 8 9 10 | <groupId>io.springfox</groupId> springfox-swagger2</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger-ui</artifactId> <version>2.8.0</version> </dependency> |
我正在使用 Spring Boot 2.4.1。但是在启动 Spring Boot 应用程序时看不到 Swagger 端点日志。
所以我实际上想要 hatoas 支持并且遇到了同样的问题。如果你有
就会发生这种情况
2 3 4 | <groupId>org.springframework.hateoas</groupId> spring-hateoas</artifactId> </dependency> |
而不是
2 3 4 | <groupId>org.springframework.boot</groupId> spring-boot-starter-hateoas</artifactId> </dependency> |
已解决,当 Swagger HATEOAS 与 Spring Boot 2.2.4.RELEASE 一起使用时,由于集成而发生此问题。RELEASE
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.hateoas.client.LinkDiscoverer; import org.springframework.hateoas.client.LinkDiscoverers; import org.springframework.hateoas.mediatype.collectionjson.CollectionJsonLinkDiscoverer; import org.springframework.http.ResponseEntity; import org.springframework.plugin.core.SimplePluginRegistry; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger.web.DocExpansion; import springfox.documentation.swagger.web.ModelRendering; import springfox.documentation.swagger.web.OperationsSorter; import springfox.documentation.swagger.web.TagsSorter; import springfox.documentation.swagger.web.UiConfiguration; import springfox.documentation.swagger.web.UiConfigurationBuilder; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public LinkDiscoverers discoverers() { List<LinkDiscoverer> plugins = new ArrayList<>(); plugins.add(new CollectionJsonLinkDiscoverer()); return new LinkDiscoverers(SimplePluginRegistry.create(plugins)); } @Bean public Docket eDesignApi(SwaggerConfigProperties swaggerConfigProperties) { return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo(swaggerConfigProperties)) .enable(Boolean.valueOf(swaggerConfigProperties.getEnabled())).select() .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build().pathMapping("/") .directModelSubstitute(LocalDate.class, String.class).genericModelSubstitutes(ResponseEntity.class) .useDefaultResponseMessages(Boolean.valueOf(swaggerConfigProperties.getUseDefaultResponseMessages())) .enableUrlTemplating(Boolean.valueOf(swaggerConfigProperties.getEnableUrlTemplating())); } @Bean UiConfiguration uiConfig(SwaggerConfigProperties swaggerConfigProperties) { return UiConfigurationBuilder.builder().deepLinking(Boolean.valueOf(swaggerConfigProperties.getDeepLinking())) .displayOperationId(Boolean.valueOf(swaggerConfigProperties.getDisplayOperationId())) .defaultModelsExpandDepth(Integer.valueOf(swaggerConfigProperties.getDefaultModelsExpandDepth())) .defaultModelExpandDepth(Integer.valueOf(swaggerConfigProperties.getDefaultModelExpandDepth())) .defaultModelRendering(ModelRendering.EXAMPLE) .displayRequestDuration(Boolean.valueOf(swaggerConfigProperties.getDisplayRequestDuration())) .docExpansion(DocExpansion.NONE).filter(Boolean.valueOf(swaggerConfigProperties.getFilter())) .maxDisplayedTags(Integer.valueOf(swaggerConfigProperties.getMaxDisplayedTags())) .operationsSorter(OperationsSorter.ALPHA) .showExtensions(Boolean.valueOf(swaggerConfigProperties.getShowExtensions())) .tagsSorter(TagsSorter.ALPHA).supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS) .validatorUrl(null).build(); } private ApiInfo apiInfo(SwaggerConfigProperties swaggerConfigProperties) { return new ApiInfoBuilder().title(swaggerConfigProperties.getTitle()) .description(swaggerConfigProperties.getDescription()).version(swaggerConfigProperties.getApiVersion()) .build(); } } |
及以下是swagger依赖
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <java.version>1.8</java.version> <swagger.version>2.9.2</swagger.version> <swagger-annotations.version>1.5.21</swagger-annotations.version> <swagger-models.version>1.5.21</swagger-models.version> <spring-plugin.version>2.0.0.BUILD-SNAPSHOT</spring-plugin.version> </properties> <dependency> <groupId>io.springfox</groupId> springfox-swagger2</artifactId> <version>${swagger.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger-ui</artifactId> <version>${swagger.version}</version> </dependency> <dependency> <groupId>io.swagger</groupId> swagger-annotations</artifactId> <version>${swagger-annotations.version}</version> </dependency> <dependency> <groupId>io.swagger</groupId> swagger-models</artifactId> <version>${swagger-models.version}</version> </dependency> |
我已经删除了这些依赖项作为解决方法并工作了:
2 3 4 5 6 7 8 9 10 11 | <groupId>io.springfox</groupId> springfox-swagger2</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency> |
如果对你有用,请告诉我。
如果你想要
2 | compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' |
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘