title: Error creating bean with name 'resourceHandlerMapping'
body: <p>I have an application with spring that use a JpaConfiguration class to deal with my database, and a WebAppMvcConfigurer class to deal with the front via json message. Both have an @Configuration and are in the same package. I have an App class in a root package with @Configuration and @ComponentScan with my main method.</p>
  
  <p>When I launch App class I get this error :</p>
  
  <pre><code>    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
      at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656)
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
      at org.springframework.context.annotation.AnnotationConfigApplicationContext.&lt;init&gt;(AnnotationConfigApplicationContext.java:89)
      at com.bnpp.creditauto.App.main(App.java:22)
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
      at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651)
      ... 14 more
  Caused by: java.lang.IllegalStateException: No ServletContext set
      at org.springframework.util.Assert.state(Assert.java:73)
      at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:533)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
      ... 15 more
  </code></pre>
  
  <p>What "works" so far is delete one of the two @Configuration in either JpaConfiguration or WebAppMvcConfigurer. If i delete the @Configuration WebApp one i can interact with my database no problem, but cant access anything from my angular application.
  If I delete the @Configuration in JpaConf the front part of the application works and I can access the json my Java application sends with my angular application no problem, but cant do anything with my database.</p>
  
  <p>Somewhere I read to change @Configuation to @WebAppConfiguration in WebAppMvcConfigurer, it does the same as removing the @Configuration, JpaConfiguration works fine and front part doesnt work.</p>
  
  <p>I checked dependencies and tried the last version without success.
  I tried to change in App : <code>@ComponentScan(basePackages = { "org.example.springproject" }, excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) })</code>
  without success too, it is the same as deleting both @Configuration in Jpa and webapp</p>
  
  <p>My app class :</p>
  
  <pre><code>package com.bnpp.creditauto;
  
  @Configuration
  @ComponentScan//("com.bnpp.creditauto")
  public class App {
  
      public static void main(String[] args) {
          ...
  }
  </code></pre>
  
  <p>JpaConfiguration class :</p>
  
  <pre><code>package com.bnpp.creditauto.config;
  
  @Configuration
  @EnableTransactionManagement
  @PropertySource("classpath:application.properties")
  public class JpaConfiguration {
    ...
  }
  </code></pre>
  
  <p>WebAppMvcConfigurer class :</p>
  
  <pre><code>package com.bnpp.creditauto.config;
  
  @Configuration
  @EnableWebMvc
  public class WebAppMvcConfigurer implements WebMvcConfigurer {
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/css/**").addResourceLocations("/css/");
      }
  
      @Override
      public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
          configurer.enable();
      }
  }
  </code></pre>