1

I read this other posting about how to add a servlet filter in Spring Boot, but I am getting a No Default Constructor error when I try to follow its example of adding an inner WebConfig class within the UiApplication.java class file.

I am trying this because adding ignoring(/api-url to the app's SecurityConfig class caused a message stating the /api-url has an empty filter list. I want to add a servlet filter for /api-url so that its filter list is no longer empty.

The code for the WebConfig inner class is:

@Configuration
public class WebConfig {

    @Bean
    public FilterRegistrationBean shallowEtagHeaderFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new ShallowEtagHeaderFilter());
        registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
        registration.addUrlPatterns("/api-url");
        return registration;
    }
}

What specific changes need to be made to the code below to enable the servlet filter to be added to /api-url without throwing the error?

The complete code for the UiApplication.java class is:

@SpringBootApplication
@Controller
public class UiApplication extends WebMvcConfigurerAdapter {

    @Configuration
    public class WebConfig {

        @Bean
        public FilterRegistrationBean shallowEtagHeaderFilter() {
            FilterRegistrationBean registration = new FilterRegistrationBean();
            registration.setFilter(new ShallowEtagHeaderFilter());
            registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
            registration.addUrlPatterns("/api-url");
            return registration;
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(UiApplication.class, args);
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
        lci.setParamName("lang");
        return lci;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }

    @Configuration
    @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    protected static class SecurityConfiguration extends WebSecurityConfigurerAdapter {

        @Override
        public void configure(WebSecurity webSecurity) throws Exception {
            webSecurity.ignoring().antMatchers("/api-url");
        }

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                .formLogin()
                .and()
                .httpBasic().and()
                .authorizeRequests()
                    .antMatchers("/").permitAll()
                    .antMatchers("/secure**").permitAll()
                    .anyRequest().authenticated();;
        }
    }
}

And the complete stack trace of the error when I try to launch the Spring Boot jar is:

2016-04-10 10:32:58.759 ERROR 5174 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) [spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) [spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112) [spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101) [spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at demo.UiApplication.main(UiApplication.java:193) [modular-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53) [modular-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:76) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:452) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:167) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    ... 14 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demo.UiApplication$WebConfig': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e]: No default constructor found; nested exception is java.lang.NoSuchMethodException: demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e.<init>()
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:232) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:213) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:89) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:77) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:235) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:222) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:85) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:207) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:55) ~[spring-boot-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5170) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_45]
    ... 1 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e]: No default constructor found; nested exception is java.lang.NoSuchMethodException: demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e.<init>()
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    ... 33 common frames omitted
Caused by: java.lang.NoSuchMethodException: demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e.<init>()
    at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_45]
    at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_45]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80) ~[spring-beans-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    ... 34 common frames omitted

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:53)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101)
    at demo.UiApplication.main(UiApplication.java:193)
    ... 6 more
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:76)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:452)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:167)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
    ... 14 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demo.UiApplication$WebConfig': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e]: No default constructor found; nested exception is java.lang.NoSuchMethodException: demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e.<init>()
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:232)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:213)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:89)
    at org.springframework.boot.context.embedded.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:77)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:235)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:222)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:85)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:207)
    at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:55)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5170)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    ... 1 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e]: No default constructor found; nested exception is java.lang.NoSuchMethodException: demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e.<init>()
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098)
    ... 33 more
Caused by: java.lang.NoSuchMethodException: demo.UiApplication$WebConfig$$EnhancerBySpringCGLIB$$f410234e.<init>()
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.getDeclaredConstructor(Class.java:2178)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80)
    ... 34 more
[root@localhost CustomLogin2]# 
Community
  • 1
  • 1
CodeMed
  • 10,414
  • 61
  • 175
  • 315

2 Answers2

4

Make your WebConfig class static:

@Configuration
public static class WebConfig { ... }

Also, do not put all of your configurations in one class, try to put them in separate classes.

Ali Dehghani
  • 39,344
  • 13
  • 147
  • 138
  • Thank you and +1. Adding the word `static` where you indicated has resulted in the app compiling. But that is half of the OP's question. How can I resolve the second half of the OP, which would confirm that the `/api-url` does indeed have a filter attached to it now? – CodeMed Apr 10 '16 at 19:09
  • Send a request to one of endpoints that starts with `api-url` with appropriate etag header and put a breakpoint in `ShallowEtagHeaderFilter#doFilterInternal`. – Ali Dehghani Apr 10 '16 at 19:16
  • Thank you. What do you mean by "appropriate etag header?" I have sent a request for `/api-url` and the result is the debug logs printing `/api-url has an empty filter list`. The actual url is `/registration-form`, but I am using the term `/api-url` in this OP to keep things generic so others can use it too. – CodeMed Apr 10 '16 at 19:19
  • Also, I looked in `UiApplication.java` and there is no `ShallowEtagHeaderFilter#doFilterInternal`, so I am not sure where to put the break point. – CodeMed Apr 10 '16 at 19:24
  • `ShallowEtagHeaderFilter` has a method called `doFilterInteral`. – Ali Dehghani Apr 10 '16 at 19:26
  • I am looking through the eclipse maven dependencies for the project to try to find the right jar containing `ShallowEtagHeaderFilter`. Any idea which jar contains it? The package is `org.springframework.web.filter.`. – CodeMed Apr 10 '16 at 19:29
  • `CTRL + SHIFT + T` then type the class name to search for class by name in eclipse – Ali Dehghani Apr 10 '16 at 19:30
  • Your configuration looks fine and the filter should be registered. That debug message is for spring security, since you've ignored the `api-url`. – Ali Dehghani Apr 10 '16 at 19:33
  • I put break points at every line inside `ShallowEtagHeaderFilter.doFilterInternal()`, and then I made another request to `/api-url` from a front-end app in a different server container, but the Spring Boot debug log still says that `/api-url has an empty filter chain`, and **the break points never stopped the program's control flow**. – CodeMed Apr 10 '16 at 19:35
  • Check your http response, do you see `ETag` header in response headers? – Ali Dehghani Apr 10 '16 at 19:41
  • The `Network tab` of the Firefox Developer Tools gives a 403 error, and the `raw headers` section for the `response` gives the following: `Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH Content-Length: 20 Date: Sun, 10 Apr 2016 19:41:48 GMT Server: Apache-Coyote/1.1 X-Application-Context: application:8001` – CodeMed Apr 10 '16 at 19:43
  • Spring security blocked the request! Are you sure you're sending the request to `/api-url`? – Ali Dehghani Apr 10 '16 at 19:49
  • Yes, the request is definitely going to `/api-url`. This whole problem emerged when I moved my AngularJS code outside the Spring Boot jar/app and into a separate Node.js container. Spring security started blocking the anonymous calls to api end points. I have tried many things to simply open up the public end points. Manually adding the servlet filter is the most recent attempt to overcome the `/api-url has an empty filter list` message that happens whenever a supposedly public api end point is called from the outside app. – CodeMed Apr 10 '16 at 19:53
  • IMO ask another question for the second part of your question and add more details about project structure – Ali Dehghani Apr 10 '16 at 19:54
  • OK. Thank you. Lemme ponder how to deal with this question. In the meantime, if you are interested in the broader question, this is actually the tangent/sidebar question to the broader question. The project structure is simple enough that I might resort to minimizing it enough to post a zip of an entire reproduceable project. Here is the link to the larger question: http://stackoverflow.com/questions/36489253/api-url-has-an-empty-filter-list-in-spring-boot-security – CodeMed Apr 10 '16 at 19:57
0

Please follow below two question which have similar question,

Answer by Steven

and a issues at Spring-Project

Community
  • 1
  • 1
Hareesh
  • 624
  • 5
  • 16