spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.Filter' available #1491

Closed paoloaq closed 7 years ago

paoloaq commented 7 years ago

The following example works with the spring-boot-starter-parent 1.4.1. However, with the spring-boot-starter-parent 1.4.2, the exception NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.Filter' occurs.

Boot Application class:

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

application.yml:

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

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>

Error with the spring-boot-starter-parent 1.4.2:

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.
ryanjbaxter commented 7 years ago

I am not able to reproduce this. I copied your pom and application properties exactly. I did notice you do not have spring-boot-starter-web as a dependency, usually you would want that included as well. If you can post a zip of the failing application or put the code on github I can try and use that to reproduce the problem.

paoloaq commented 7 years ago

The spring-boot-starter-web, 1.4.2.RELEASE, is resolved in the effective pom. Anyway, adding the spring-boot-starter-web to the pom file, does not change the situation.

Here is the code: eureka-server_issue-1491

ryanjbaxter commented 7 years ago

It must be something in your environment because the app starts fine for me.

paoloaq commented 7 years ago

This is my environment:

I also tried to run it from the command line:

mvn spring-boot: run

The error is the same as in the IDE: NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.Filter' available.

However, another strange thing is the result of these commands from terminal:

mvn install
java -jar target/EurekaServer-0.0.1-SNAPSHOT.jar

Error:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.IllegalArgumentException: Unable to load [org.springframework.context.ApplicationContextInitializer] factories from location [META-INF/spring.factories]
    at org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(SpringFactoriesLoader.java:124)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:402)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:394)
    at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:261)
    at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
    at com.example.springMicroservices.EurekaServerApplication.main(EurekaServerApplication.java:11)
    ... 8 more
Caused by: java.util.zip.ZipException: invalid code lengths set
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
    at org.springframework.boot.loader.jar.ZipInflaterInputStream.read(ZipInflaterInputStream.java:52)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at java.util.Properties$LineReader.readLine(Properties.java:435)
    at java.util.Properties.load0(Properties.java:353)
    at java.util.Properties.load(Properties.java:341)
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:139)
    at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:121)
    at org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(SpringFactoriesLoader.java:117)
    ... 15 more

Thanks for your help!

spencergibb commented 7 years ago

Bad jar? try cleaning your maven repo.

paoloaq commented 7 years ago

@spencergibb thank you so much !!! rm -r $HOME/.m2 has completely solved my issue! Sorry for the inconvenience and thank you again! :)

kuldeepkrsharma029 commented 7 years ago

I also faced the same problem, and yes rm -r $HOME/.m2 worked for me also. Thanks a lot guys.

elninojk commented 7 years ago

Tried with deleting only the repo, still not working. After deleting m2 folder itself , started working. Bit strange though ???

AprilGH commented 6 years ago

@kuldeepkrsharma029 I am a beginner. How do I do this rm -r $ HOME / .m2

AprilGH commented 6 years ago

@kuldeepkrsharma029 Where to execute?