NoSuchBeanDefinitionException:没有“javax.servlet.Filter”类型的合格bean可用

NoSuchBeanDefinitionException:没有“javax.servlet.Filter”类型的合格bean可用,java,spring,spring-boot,spring-cloud,spring-cloud-netflix,Java,Spring,Spring Boot,Spring Cloud,Spring Cloud Netflix,Eureka服务器-Camden.SR2-Spring Boot Starter 1.4.2.0版本 我在尝试使用Eureka服务器运行Spring Boot Starter 1.4.2.RELEASE时遇到以下错误: 2016-11-21 22:33:53.420 INFO 20635 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.

Eureka服务器-Camden.SR2-Spring Boot Starter 1.4.2.0版本

我在尝试使用Eureka服务器运行Spring Boot Starter 1.4.2.RELEASE时遇到以下错误:

2016-11-21 22:33:53.420  INFO 20635 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2177849e: startup date [Mon Nov 21 22:33:53 CET 2016]; root of context hierarchy
2016-11-21 22:33:53.836  INFO 20635 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-11-21 22:33:53.894  INFO 20635 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fc4b31a3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.2.RELEASE)

2016-11-21 22:33:59.402  INFO 20635 --- [           main] i.v.p.s.EurekaServerApplication          : No active profile set, falling back to default profiles: default
2016-11-21 22:33:59.422  INFO 20635 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5c18016b: startup date [Mon Nov 21 22:33:59 CET 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2177849e
2016-11-21 22:34:00.348  WARN 20635 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2016-11-21 22:34:00.655  INFO 20635 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=e1bdaab3-6fb3-3c45-9078-5ee488116098
2016-11-21 22:34:00.772  INFO 20635 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-11-21 22:34:00.936  INFO 20635 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fc4b31a3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-11-21 22:34:01.378  INFO 20635 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8761 (http)
2016-11-21 22:34:01.397  INFO 20635 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-11-21 22:34:01.399  INFO 20635 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2016-11-21 22:34:01.589  INFO 20635 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-11-21 22:34:01.590  INFO 20635 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2168 ms
2016-11-21 22:34:02.107 ERROR 20635 --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter    : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'traceFilterRegistration' defined in org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration: Unsatisfied dependency expressed through method 'traceFilterRegistration' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.Filter' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webRequestLoggingFilter)}
2016-11-21 22:34:02.141  WARN 20635 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
2016-11-21 22:34:02.315 ERROR 20635 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method traceFilterRegistration in org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration required a bean of type 'javax.servlet.Filter' that could not be found.
    - Bean method 'resourceUrlEncodingFilter' in 'FreeMarkerAutoConfiguration.FreeMarkerWebConfiguration' not loaded because @ConditionalOnEnabledResourceChain did not find class org.webjars.WebJarAssetLocator


Action:

Consider revisiting the conditions above or defining a bean of type 'javax.servlet.Filter' in your configuration.
pom.xml:

启动应用程序类:

注意:如果我将spring boot starter父级设置为1.4.1.0版本,那么一切都可以正常工作

这是我的环境:

MacOS Sierra 10.12.1 Spring工具套件-版本:3.8.2.RELEASE构建Id:201610040743-平台:EclipseNeon.1 4.6.1
在GitHub上打开了一个问题:


通过清理maven repo:rm-r$HOME/.m2解决了这个问题,您可以创建这个bean:

@Bean
public Filter webRequestLoggingFilter() {
    return new CommonsRequestLoggingFilter();
}

我能够通过调整SpringBoot和SpringCloud的版本来解决这个问题,特别是SpringBootStarter父版本和SpringCloud依赖关系

为了查看这些文件的最新兼容版本,我创建了一个eureka服务器项目,然后查看了生成的pom.xml

要从上面的链接创建eureka项目,请执行以下操作:

选择我使用的最新spring引导版本 在依赖项中键入“eureka”,然后选择eureka服务器
单击“浏览”按钮查看生成的pom.xml。

spring boot和spring cloud之间应该存在不匹配的版本。如果使用SpringBootVersion2.2.0.RELEASE,则必须使用SpringCloud版本Hoxton.RC1。如果使用SpringBootVersion2.1.9.RELEASE,则必须使用SpringCloudVersionGreenwich.SR3

以下是示例:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
我换衣服 格林威治释放 到 Hoxton.SR8
通过匹配Spring Boot和Spring Cloud的版本,您可以解决Spring Boot+Spring Cloud带来的许多问题。有关版本矩阵,请参阅此链接。

这可能是有害的,许多人在.m2目录中有复杂的settings.xml文件,比如我和其他通过vpn下载的自定义依赖项。完美的解决方案是移除特定的罐子。但是哪一个呢?
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}
@Bean
public Filter webRequestLoggingFilter() {
    return new CommonsRequestLoggingFilter();
}
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>