Swagger2与Spring MVC的集成

时间:2017-05-29 06:34:05

标签: spring-mvc swagger-2.0

我正在尝试将swagger2与我的应用程序Spring MVC集成,但会出现以下异常

Error创建名为

的bean
  

' documentationPluginsBootstrapper'在URL [jar:file:/ D:/softwares/apache-tomcat-8.5.6/webapps/ksackout/WEB-INF/lib/springfox-spring-web-2.6.1.jar!/ springfox / documentation / spring中定义/web/plugins/DocumentationPluginsBootstrapper.class]:通过构造函数参数1表示的不满意的依赖关系:创建名称为' webMvcRequestHandlerProvider'在URL [jar:file:/ D:/softwares/apache-tomcat-8.5.6/webapps/ksackout/WEB-INF/lib/springfox-spring-web-2.6.1.jar!/ springfox / documentation / spring中定义/web/plugins/WebMvcRequestHandlerProvider.class]:通过构造函数参数0表示的不满意的依赖:没有为依赖项[java.util.List]找到类型[java.util.List]的限定bean:预期至少有1个符合autowire的bean这种依赖的候选人。依赖注释:{};嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项[java.util.List]找到类型为[java.util.List]的限定bean:期望至少有一个bean,它有资格作为此依赖项的autowire候选者。依赖注释:{};嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为' webMvcRequestHandlerProvider'在URL

中定义

这是我的pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd">     4.0.0

<parent>
    <artifactId>ksa-ckout-build</artifactId>
    <groupId>com.ksa.mcommerce</groupId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../ksa-ckout-build/pom.xml</relativePath>
</parent>

<groupId>com.ksa.ckout.web</groupId>
<artifactId>ksa-ckout-web</artifactId>
<packaging>war</packaging>

<name>ckout web</name>
<url>http://maven.apache.org</url>




<build>
    <!-- Generate compiled stuff in the folder used for developing mode -->
    <!-- <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory> -->
    <finalName>${war.context}</finalName>
    <plugins>

        <!-- Copy static web files before executing gwt:run -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>exploded</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <webappDirectory>${webappDirectory}</webappDirectory>
            </configuration>
        </plugin>

    </plugins>
</build>

<dependencies>
    <!-- https://mvnrepository.com/artifact/com.mangofactory/swagger-springmvc -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.0</version>
    </dependency>
    <dependency>
        <groupId>com.ksa.ckout.service</groupId>
        <artifactId>ksa-ckout-service</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.ksa.ckout.api</groupId>
        <artifactId>ksa-ckout-api</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.ksa.ckout.aop</groupId>
        <artifactId>ksa-ckout-aop</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.ksa.ckout.security</groupId>
        <artifactId>ksa-ckout-security</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>
    <!-- Spring and Transactions -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>

    <!-- Spring Security -->

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring-security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring-security.version}</version>
    </dependency>

    <!-- <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-jersey-jaxrs</artifactId> 
        <exclusions> <exclusion> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> 
        </exclusion> <exclusion> <groupId>com.sun.jersey</groupId> <artifactId>jersey-multipart</artifactId> 
        </exclusion> </exclusions> </dependency> -->

    <!--<dependency> <groupId>com.wordnik</groupId> <artifactId>swagger-core</artifactId> 
        <version>1.5.3-M1</version> </dependency> -->
    <!--<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> 
        <version>2.0.2</version> </dependency> -->

    <!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>${hsqldb.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.hynnet/sqljdbc4-chs -->
    <dependency>
        <groupId>com.hynnet</groupId>
        <artifactId>sqljdbc4-chs</artifactId>
        <version>${sqljdbc.version}</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz -->
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>${quartz.version}</version>
    </dependency>



    <!-- Logging with SLF4J & LogBack <dependency> <groupId>org.slf4j</groupId> 
        <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> <scope>compile</scope> 
        </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> 
        <version>${logback.version}</version> <scope>runtime</scope> </dependency> -->

    <!-- Hibernate -->
    <!-- <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> 
        <version>${hibernate.version}</version> </dependency> -->



    <!-- Test Artifacts -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring-framework.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>${mockito.version}</version>
        <scope>test</scope>
    </dependency>

    <!-- web -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet.version}</version>
        <scope>provided</scope>
    </dependency>


    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-spring</artifactId>
        <version>${jersey.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-asm</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.jersey-test-framework</groupId>
        <artifactId>jersey-test-framework-grizzly2</artifactId>
        <version>${jersey.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.ws.rs/jsr311-api -->
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>jsr311-api</artifactId>
        <version>${jaxrs.version}</version>
    </dependency>

    <!-- <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> 
        <version>${gson.version}</version> </dependency> <dependency> <groupId>javax.xml</groupId> 
        <artifactId>jaxb-api</artifactId> <version>2.1</version> </dependency> <dependency> 
        <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> 
        <version>1.3</version> </dependency> -->

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.sun.jersey.contribs/jersey-multipart -->
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <!-- PowerMock dependency -->
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>${powermock.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId>
        <version>${powermock.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4-rule-agent</artifactId>
        <version>${powermock.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-javaagent</artifactId>
        <version>${powermock.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>


<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <webappDirectory>${project.build.directory}/${project.build.finalName}
    </webappDirectory>
</properties>

spring.xml

中添加了以下配置bean

如果有人可以提供帮助,

会很感激

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我解决了这个问题,将注解@NonRepositoryBean放在我的BaseRepository接口上。

@NoRepositoryBean
public interface BaseRepository<E> extends CrudRepository<E, Long> {

    Collection<E> findAll();

    void deleteById(Long id);

}

希望这会有所帮助!