找不到 SwaggerWelcomeCommon

SwaggerWelcomeCommon could not be found

正在尝试将 Springdoc 添加到 spring-boot-2.6.2 项目。 嵌入式码头服务器上的应用程序 运行s。 执行器 运行 可以接受以下 pom.xml 设置。

当我尝试 运行 应用程序时,出现以下错误。由于我认为这是由于其中一个依赖关系而发生的,因此我尝试组织依赖关系。

Description:

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.


Action:

Consider defining a bean of type 'org.springdoc.webmvc.ui.SwaggerWelcomeCommon' in your configuration.

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>demo</groupId>
        <artifactId>demo</artifactId>
        <version>demo-1.01</version>
    </parent>

    <artifactId>demo</artifactId>
    <packaging>war</packaging>

    <properties>
        <package.plantbase>dev</package.plantbase>
        <ojdbc6.version>11.2.0.4</ojdbc6.version>
        <jetty.version>9.4.43.v20210629</jetty.version>
        <jjwt.version>0.9.1</jjwt.version>
        <reflection.version>0.9.11</reflection.version>
        <lombok.version>1.18.4</lombok.version>
        <plexus.version>2.5.2</plexus.version>
        <java.version>11</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-quartz</artifactId>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
            <exclusions>
                <!--use jetty instead of tomcat -->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.4.5</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>${ojdbc6.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.4</version>
        </dependency>

    </dependencies>


    <profiles>
        <profile>
            <id>devpc-runAsPlantBase</id>
            <activation>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <version>${enforcer.version}</version>
                        <executions>
                            <execution>
                                <id>enforce-configuration-setup</id>
                                <goals>
                                    <goal>enforce</goal>
                                </goals>
                                <configuration>
                                    <rules>
                                        <requireFilesExist>
                                            <files>
                                                <file>../configuration/contexts</file>
                                                <file>../configuration/properties/${package.plantbase}</file>
                                            </files>
                                        </requireFilesExist>
                                    </rules>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <version>${jetty.version}</version>
                        <configuration>
                            <testClassesDirectory>${project.basedir}/target/resources</testClassesDirectory>
                            <useTestClasspath>true</useTestClasspath>
                            <webAppXml>${project.build.outputDirectory}/jetty-web.xml</webAppXml>
                            <stopKey>foo</stopKey>
                            <stopPort>9999</stopPort>
                        </configuration>
                    </plugin>



                </plugins>
                <resources>
                    <!--Use the data from the configuration folders... -->

                    <resource>
                        <directory>../configuration/properties/${package.plantbase}</directory>
                        <filtering>true</filtering>
                        <!--<targetPath>${project.build.directory}/classes/</targetPath> -->
                    </resource>
                    <resource>
                        <directory>../configuration/contexts</directory>
                        <filtering>true</filtering>
                        <!--<targetPath>${project.build.directory}/tmp</targetPath> -->
                    </resource>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </build>
        </profile>
    </profiles>

    <build>
        <defaultGoal>install</defaultGoal>
        <resources>
            <resource>
                <directory>../configuration/properties/${package.plantbase}</directory>
                <targetPath>${project.build.outputDirectory}</targetPath>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archive>
                        <manifest>
                            <mainClass>${start-class}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <verbose>true</verbose>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这是因为 springdoc.use-management-port 属性 下面 class 的条件。我已将其设置为 true,因此未设置 bean。我把它改成false,问题就解决了。

SwaggerConfig.class:

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(
    name = {"springdoc.use-management-port"},
    havingValue = "false",
    matchIfMissing = true
)
SwaggerWelcomeWebMvc swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, SpringWebProvider springWebProvider) {
    return new SwaggerWelcomeWebMvc(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters, springWebProvider);
}