简体   繁体   English

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

[英]NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.Filter' available

Eureka Server - Camden.SR2 - Spring Boot Starter 1.4.2.RELEASE Eureka Server - Camden.SR2 - Spring Boot Starter 1.4.2.RELEASE

I am getting the following error while trying to run Spring Boot Starter 1.4.2.RELEASE with Eureka server:尝试使用 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 : 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>

    <groupId>com.example.spring.microservices</groupId>
    <artifactId>EurekaServer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>EurekaServer</name>
    <description>Eureka discovery server example</description>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>

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

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

application.yml :应用程序.yml :

server:
  port: 8761
spring:
  application:
    name: eureka-server1
eureka:
  client:
    registerWithEureka: false
    fetch-registry: false
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

Boot Application class :启动应用程序类

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

NOTE : if I set the spring-boot-starter-parent to the 1.4.1.RELEASE everything works.注意:如果我将spring-boot-starter-parent设置为 1.4.1.RELEASE 一切正常。


This is my environment:这是我的环境:

  • MacOS Sierra 10.12.1 MacOS 塞拉利昂 10.12.1
  • Spring Tool Suite - Version: 3.8.2.RELEASE (Build Id: 201610040743 - Platform: Eclipse Neon.1 (4.6.1)) Spring Tool Suite - 版本:3.8.2.RELEASE(构建 ID:201610040743 - 平台:Eclipse Neon.1 (4.6.1))

There should be a mismatch version between spring boot and spring cloud. spring boot 和 spring cloud 之间应该存在不匹配的版本。 If you use spring boot version 2.2.0.RELEASE you have to use spring cloud version Hoxton.RC1.如果您使用 spring boot 版本 2.2.0.RELEASE,则必须使用 spring cloud 版本 Hoxton.RC1。 If you use spring boot version 2.1.9.RELEASE, you have to use spring cloud version Greenwich.SR3.如果使用spring boot 2.1.9.RELEASE版本,则必须使用spring cloud版本Greenwich.SR3。

Below is the sample:下面是示例:

<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>

Opened an issue on GitHub: #1491 .在 GitHub 上打开了一个问题: #1491

Solved by cleaning the maven repo: rm -r $HOME/.m2通过清理 maven repo 解决: rm -r $HOME/.m2

I was able to solve this problem by aligning my versions of spring-boot and spring-cloud, specifically spring-boot-starter-parent and spring-cloud-dependencies .我能够通过调整我的 spring-boot 和 spring-cloud 版本来解决这个问题,特别是spring-boot-starter-parentspring-cloud-dependencies

To see the latest compatible versions of these I used SpringInitializr to create a eureka server project and then looked at the generated pom.xml.为了查看这些的最新兼容版本,我使用SpringInitializr创建了一个eureka服务器项目,然后查看了生成的 pom.xml。

To create a eureka project from the link above:从上面的链接创建一个尤里卡项目:

  • Select the spring boot version (I use the latest)选择spring boot版本(我用的是最新的)
  • Type 'eureka' into the Dependencies and select eureka-server在依赖项中输入“eureka”并选择 eureka-server

Click the 'Explore' button to view the generated pom.xml.单击“探索”按钮查看生成的 pom.xml。

you can create this bean :你可以创建这个bean:

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

我将 <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version> 更改为 <spring-cloud.version>Hoxton.SR8</spring-cloud.version> 并且工作正常。

You can solve many issues like this coming with (Spring Boot + Spring Cloud) by matching versions of Spring Boot and Spring Cloud.您可以通过匹配 Spring Boot 和 Spring Cloud 的版本来解决(Spring Boot + Spring Cloud)带来的许多问题。 Please refer this link for version matrix.请参阅此链接以获取版本矩阵。 https://spring.io/projects/spring-cloud https://spring.io/projects/spring-cloud

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoSuchBeanDefinitionException:没有可用的“javax.persistence.EntityManagerFactory”类型的合格 bean - NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManagerFactory' available 个人资料有问题吗? NoSuchBeanDefinitionException:没有名为“entityManagerFactory”的bean可用并且没有符合条件的bean类型 - is there a problem with profiles? NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available and No qualifying bean of type Spring NoSuchBeanDefinitionException:没有可用类型 [@Repository class] 的 Qualifying Bean - Spring NoSuchBeanDefinitionException: No Qualifying Bean of Type [@Repository class] available NoSuchBeanDefinitionException:没有类型合格的bean(存储库) - NoSuchBeanDefinitionException: No qualifying bean of type (repository) NoSuchBeanDefinitionException:找不到类型合格的bean - NoSuchBeanDefinitionException: No qualifying bean of type found NoSuchBeanDefinitionException: 没有“XInterceptor”类型的合格 bean - NoSuchBeanDefinitionException: No qualifying bean of type "XInterceptor" NoSuchBeanDefinitionException: 没有“int”类型的合格 bean - NoSuchBeanDefinitionException: No qualifying bean of type 'int' NoSuchBeanDefinitionException:没有可用类型的限定bean:预期至少有1个bean有资格作为autowire候选者 - NoSuchBeanDefinitionException: No qualifying bean of type available: expected at least 1 bean which qualifies as autowire candidate javax.servlet.Filter响应默认头 - javax.servlet.Filter response default headers 带有javax.servlet.Filter的DelegatingFilterProx不起作用 - DelegatingFilterProx With javax.servlet.Filter Not Working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM