2017-02-06 30 views
2

我试图测试使用Springboot 1.5我不断收到对未发现FilterRegestionBean类异常的服务时发现DEF FilterRegistrationBean。Springboot 1.5没有CLASSE试图测试服务

@RunWith(SpringRunner.class) 
@SpringBootTest 
class ApiServiceSpecTest { 

    @Autowired 
    ApiService apiService; 

    @Test 
    public void testGetApis() { 
     List<Api> apis = this.apiService.getApis("KFS") 
     given(this.apiService.getApis("KFS")).willReturn("some stuff") 
    assertThat(!apis.empty) 
} 

我的build.gradle样子:

compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version:'1.1.1.RELEASE' 
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'1.5.1.RELEASE' 
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version:'1.5.1.RELEASE' 
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version:'1.5.1.RELEASE' 
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version:'1.5.1.RELEASE' 
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'1.5.1.RELEASE') 

我检查的文件,感觉就像我已经实现了的例子,但我不能让它运行。任何帮助将不胜感激。

回答

0

FilterRegistrationBean在春季启动1.4.x中被弃用,在春季启动1.5最有可能去掉(它不仅改变了包)。您的spring-cloud-sleuth依赖性可能基于Spring Boot 1.4,因此当您尝试使用旧包中的FilterRegistrationBean类尝试实例化跟踪筛选器时,您会遇到运行时问题。

解决方案:将您的spring-cloud-sleuth依赖关系更新为今天刚刚出来的1.1.2.RELEASE:Release和相关的Github issue

+0

非常感谢! – Ryan

0

在春季启动1.5及更高版本,他们已经搬到了FilterRegistrationBean类。我解决它通过改变我的import语句 -

进口 org.springframework.boot.context.embedded.FilterRegistrationBean;

进口org.springframework.boot.web.servlet.FilterRegistrationBean;

和这个工作。这适用于弹簧引导1.5.1版本和1.5.2版本。

来源 - spring boot FilterReistrationBean