找不到SwaggerWelcomeCommon

bybem2ql  于 2022-11-06  发布在  其他
关注(0)|答案(2)|浏览(325)

正在尝试将Springdoc添加到spring-boot-2.6.2项目。应用程序在嵌入式Jetty服务器上运行。Actuator在下面的pom.xml设置下运行正常。
当我尝试运行应用程序时,发生了下面的错误。因为我认为这是因为其中一个依赖项,所以我尝试组织依赖项。

  1. Description:
  2. Parameter 3 of method indexPageTransformer in org.springdoc.webmvc.ui.SwaggerConfig required a bean of type 'org.springdoc.webmvc.ui.SwaggerWelcomeCommon' that could not be found.
  3. Action:
  4. Consider defining a bean of type 'org.springdoc.webmvc.ui.SwaggerWelcomeCommon' in your configuration.

pom.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <parent>
  7. <groupId>demo</groupId>
  8. <artifactId>demo</artifactId>
  9. <version>demo-1.01</version>
  10. </parent>
  11. <artifactId>demo</artifactId>
  12. <packaging>war</packaging>
  13. <properties>
  14. <package.plantbase>dev</package.plantbase>
  15. <ojdbc6.version>11.2.0.4</ojdbc6.version>
  16. <jetty.version>9.4.43.v20210629</jetty.version>
  17. <jjwt.version>0.9.1</jjwt.version>
  18. <reflection.version>0.9.11</reflection.version>
  19. <lombok.version>1.18.4</lombok.version>
  20. <plexus.version>2.5.2</plexus.version>
  21. <java.version>11</java.version>
  22. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  23. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  24. </properties>
  25. <dependencies>
  26. <dependency>
  27. <groupId>org.springframework.boot</groupId>
  28. <artifactId>spring-boot-starter-security</artifactId>
  29. </dependency>
  30. <dependency>
  31. <groupId>org.springframework.boot</groupId>
  32. <artifactId>spring-boot-starter-data-jpa</artifactId>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-starter-quartz</artifactId>
  37. </dependency>
  38. <dependency>
  39. <groupId>org.hibernate</groupId>
  40. <artifactId>hibernate-envers</artifactId>
  41. </dependency>
  42. <dependency>
  43. <groupId>org.springframework.boot</groupId>
  44. <artifactId>spring-boot-starter</artifactId>
  45. <exclusions>
  46. <exclusion>
  47. <groupId>org.springframework.boot</groupId>
  48. <artifactId>spring-boot-starter-logging</artifactId>
  49. </exclusion>
  50. </exclusions>
  51. </dependency>
  52. <dependency>
  53. <groupId>org.springframework.boot</groupId>
  54. <artifactId>spring-boot-starter-log4j2</artifactId>
  55. </dependency>
  56. <dependency>
  57. <groupId>org.springframework.boot</groupId>
  58. <artifactId>spring-boot-starter-data-rest</artifactId>
  59. <exclusions>
  60. <!--use jetty instead of tomcat -->
  61. <exclusion>
  62. <groupId>org.springframework.boot</groupId>
  63. <artifactId>spring-boot-starter-tomcat</artifactId>
  64. </exclusion>
  65. </exclusions>
  66. </dependency>
  67. <dependency>
  68. <groupId>org.springframework.boot</groupId>
  69. <artifactId>spring-boot-starter-jetty</artifactId>
  70. <scope>provided</scope>
  71. </dependency>
  72. <dependency>
  73. <groupId>org.springframework.boot</groupId>
  74. <artifactId>spring-boot-starter-jdbc</artifactId>
  75. </dependency>
  76. <dependency>
  77. <groupId>org.projectlombok</groupId>
  78. <artifactId>lombok</artifactId>
  79. <scope>provided</scope>
  80. </dependency>
  81. <dependency>
  82. <groupId>org.modelmapper</groupId>
  83. <artifactId>modelmapper</artifactId>
  84. <version>2.4.5</version>
  85. </dependency>
  86. <dependency>
  87. <groupId>org.springframework.boot</groupId>
  88. <artifactId>spring-boot-starter-test</artifactId>
  89. <scope>test</scope>
  90. </dependency>
  91. <dependency>
  92. <groupId>com.oracle</groupId>
  93. <artifactId>ojdbc6</artifactId>
  94. <version>${ojdbc6.version}</version>
  95. <scope>compile</scope>
  96. </dependency>
  97. <dependency>
  98. <groupId>org.springframework.boot</groupId>
  99. <artifactId>spring-boot-starter-actuator</artifactId>
  100. </dependency>
  101. <dependency>
  102. <groupId>org.springframework.boot</groupId>
  103. <artifactId>spring-boot-starter-web</artifactId>
  104. <exclusions>
  105. <exclusion>
  106. <groupId>org.springframework.boot</groupId>
  107. <artifactId>spring-boot-starter-tomcat</artifactId>
  108. </exclusion>
  109. </exclusions>
  110. </dependency>
  111. <dependency>
  112. <groupId>org.springdoc</groupId>
  113. <artifactId>springdoc-openapi-ui</artifactId>
  114. <version>1.6.4</version>
  115. </dependency>
  116. </dependencies>
  117. <profiles>
  118. <profile>
  119. <id>devpc-runAsPlantBase</id>
  120. <activation>
  121. </activation>
  122. <build>
  123. <plugins>
  124. <plugin>
  125. <artifactId>maven-enforcer-plugin</artifactId>
  126. <version>${enforcer.version}</version>
  127. <executions>
  128. <execution>
  129. <id>enforce-configuration-setup</id>
  130. <goals>
  131. <goal>enforce</goal>
  132. </goals>
  133. <configuration>
  134. <rules>
  135. <requireFilesExist>
  136. <files>
  137. <file>../configuration/contexts</file>
  138. <file>../configuration/properties/${package.plantbase}</file>
  139. </files>
  140. </requireFilesExist>
  141. </rules>
  142. </configuration>
  143. </execution>
  144. </executions>
  145. </plugin>
  146. <plugin>
  147. <groupId>org.eclipse.jetty</groupId>
  148. <artifactId>jetty-maven-plugin</artifactId>
  149. <version>${jetty.version}</version>
  150. <configuration>
  151. <testClassesDirectory>${project.basedir}/target/resources</testClassesDirectory>
  152. <useTestClasspath>true</useTestClasspath>
  153. <webAppXml>${project.build.outputDirectory}/jetty-web.xml</webAppXml>
  154. <stopKey>foo</stopKey>
  155. <stopPort>9999</stopPort>
  156. </configuration>
  157. </plugin>
  158. </plugins>
  159. <resources>
  160. <!--Use the data from the configuration folders... -->
  161. <resource>
  162. <directory>../configuration/properties/${package.plantbase}</directory>
  163. <filtering>true</filtering>
  164. <!--<targetPath>${project.build.directory}/classes/</targetPath> -->
  165. </resource>
  166. <resource>
  167. <directory>../configuration/contexts</directory>
  168. <filtering>true</filtering>
  169. <!--<targetPath>${project.build.directory}/tmp</targetPath> -->
  170. </resource>
  171. <resource>
  172. <directory>src/main/resources</directory>
  173. <filtering>true</filtering>
  174. </resource>
  175. </resources>
  176. </build>
  177. </profile>
  178. </profiles>
  179. <build>
  180. <defaultGoal>install</defaultGoal>
  181. <resources>
  182. <resource>
  183. <directory>../configuration/properties/${package.plantbase}</directory>
  184. <targetPath>${project.build.outputDirectory}</targetPath>
  185. <includes>
  186. <include>**/*.properties</include>
  187. <include>**/*.yml</include>
  188. </includes>
  189. </resource>
  190. <resource>
  191. <directory>src/main/resources</directory>
  192. <filtering>true</filtering>
  193. </resource>
  194. </resources>
  195. <testResources>
  196. <testResource>
  197. <directory>src/test/resources</directory>
  198. <filtering>true</filtering>
  199. </testResource>
  200. </testResources>
  201. <plugins>
  202. <plugin>
  203. <groupId>org.springframework.boot</groupId>
  204. <artifactId>spring-boot-maven-plugin</artifactId>
  205. </plugin>
  206. <plugin>
  207. <groupId>org.apache.maven.plugins</groupId>
  208. <artifactId>maven-war-plugin</artifactId>
  209. <configuration>
  210. <failOnMissingWebXml>false</failOnMissingWebXml>
  211. <archive>
  212. <manifest>
  213. <mainClass>${start-class}</mainClass>
  214. </manifest>
  215. </archive>
  216. </configuration>
  217. </plugin>
  218. <plugin>
  219. <groupId>org.apache.maven.plugins</groupId>
  220. <artifactId>maven-compiler-plugin</artifactId>
  221. <version>3.8.1</version>
  222. <configuration>
  223. <source>${java.version}</source>
  224. <target>${java.version}</target>
  225. <verbose>true</verbose>
  226. <fork>true</fork>
  227. </configuration>
  228. </plugin>
  229. </plugins>
  230. </build>
  231. </project>
lrl1mhuk

lrl1mhuk1#

这是因为下面类中的条件springdoc.use-management-port属性。我已经将其设置为true,所以没有设置bean。我将其更改为false,问题就解决了。
SwaggerConfig.class:

  1. @Bean
  2. @ConditionalOnMissingBean
  3. @ConditionalOnProperty(
  4. name = {"springdoc.use-management-port"},
  5. havingValue = "false",
  6. matchIfMissing = true
  7. )
  8. SwaggerWelcomeWebMvc swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, SpringWebProvider springWebProvider) {
  9. return new SwaggerWelcomeWebMvc(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters, springWebProvider);
  10. }
06odsfpq

06odsfpq2#

当您设置:

  1. springdoc.use-management-port=true

如果您尚未执行以下操作,请同时创建单独管理端口:

  1. management.server.port=9090

所有相关属性:

  1. springdoc.show-actuator=true
  2. springdoc.use-management-port=true
  3. management.server.port=9090
  4. management.endpoints.web.exposure.include=openapi, swagger-ui

相关问题