没有类型为[org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping]的合格bean

时间:2018-10-05 21:34:03

标签: spring cucumber swagger

我有一个配置了swagger的spring boot应用程序。运行黄瓜测试时出现错误。配置如下:

@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {  
}

@Category(IntegrationTest.class)
@RunWith(Cucumber.class)
@ContextConfiguration("classpath:cucumber-spring-beans.xml")
@CucumberOptions(snippets = SnippetType.CAMELCASE, strict = true, monochrome = true, tags = {"~@ManualTest", "~@SlowTest", "~@IgnoreTest", "~@AdHoc", "@IntegrationTest"}, 
features = {CucumberRunnerUtil.CukeFormat.FEATURE_FILE_LOCATION},
plugin = {"pretty", CucumberRunnerUtil.CukeFormat.CD_HTML_REPORT_INTEGRATION, 
        CucumberRunnerUtil.CukeFormat.CD_JSON_RESULTS_INTEGRATION + "integration-test-reports.json",
        CucumberRunnerUtil.CukeFormat.CD_JUNIT_XML_REPORT_INTEGRATION + "integration-test-reports.xml"})
public class RunIntegrationCukeTest {



}

cucumber-spring-beans.xml:

<context:component-scan base-package="org.springframework.samples.mvc" />
<context:annotation-config/>

    <context:annotation-config/>
    <mvc:annotation-driven/>

    <context:component-scan base-package="com...." >
        <context:exclude-filter type="assignable" expression="com...."/>
    </context:component-scan>

    <context:component-scan base-package="com...." >

    </context:component-scan>

1 个答案:

答案 0 :(得分:0)

从Cucumber-spring-beans.xml中排除了与招摇相关的Java配置类的窍门:

<context:component-scan base-package="...webservice.resource" >
        <context:exclude-filter type="assignable" expression="...webservice.resource.Application"/>
        <context:exclude-filter type="assignable" expression="...webservice.resource.SwaggerConfig"/>
        <context:exclude-filter type="assignable" expression="...webservice.resource.JerseyConfig"/>
        <context:exclude-filter type="assignable" expression="...webservice.resource.CombinedResourceProvider"/>    
    </context:component-scan>