springSecurityFilterChain - ObjectPostProcessor is a required bean Exception











up vote
1
down vote

favorite












I am building a Spring Boot application with Spring Security (spring-boot-starter-web and spring-boot-starter-security). I receive the following error from my application during boot:



    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:625) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:455) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
...


My application class consists of the following:



@SpringBootApplication
public class CustomPropertiesApplication {

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


The bean in this next class appears to be the issue. If it's excluded then the application will boot without error.



@Configuration
@EnableWebSecurity
public class MyConfig extends WebSecurityConfigurerAdapter {

@Bean
public CustomPropertyPlaceholderConfigurer propertyConfigurer(ApplicationContext context) {
return new CustomPropertyPlaceholderConfigurer();
}

}


Right now this CustomPropertyPlaceholderConfigurer class does nothing, I have some legacy classes that are similar, but in trying to troubleshoot this issue I eliminated everything else from my test application.



public class CustomPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
}


I'm at a loss of what to try next. I've looked for details in Spring Security and Spring Boot about building a custom property placeholder configurer, but I didn't find anything useful.



Versions: Spring Boot - 2.1.0.RELEASE | Spring Security - 5.1.1.RELEASE | JDK 1.8



Also, I realize this app doesn't really do anything, there is a much larger application that has much more complicated logic, and this sample app here is just to replicate my issue to make it small for stackoverflow.










share|improve this question




























    up vote
    1
    down vote

    favorite












    I am building a Spring Boot application with Spring Security (spring-boot-starter-web and spring-boot-starter-security). I receive the following error from my application during boot:



        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:625) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:455) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    ...


    My application class consists of the following:



    @SpringBootApplication
    public class CustomPropertiesApplication {

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


    The bean in this next class appears to be the issue. If it's excluded then the application will boot without error.



    @Configuration
    @EnableWebSecurity
    public class MyConfig extends WebSecurityConfigurerAdapter {

    @Bean
    public CustomPropertyPlaceholderConfigurer propertyConfigurer(ApplicationContext context) {
    return new CustomPropertyPlaceholderConfigurer();
    }

    }


    Right now this CustomPropertyPlaceholderConfigurer class does nothing, I have some legacy classes that are similar, but in trying to troubleshoot this issue I eliminated everything else from my test application.



    public class CustomPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
    }


    I'm at a loss of what to try next. I've looked for details in Spring Security and Spring Boot about building a custom property placeholder configurer, but I didn't find anything useful.



    Versions: Spring Boot - 2.1.0.RELEASE | Spring Security - 5.1.1.RELEASE | JDK 1.8



    Also, I realize this app doesn't really do anything, there is a much larger application that has much more complicated logic, and this sample app here is just to replicate my issue to make it small for stackoverflow.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am building a Spring Boot application with Spring Security (spring-boot-starter-web and spring-boot-starter-security). I receive the following error from my application during boot:



          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
      at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:625) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:455) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
      ...


      My application class consists of the following:



      @SpringBootApplication
      public class CustomPropertiesApplication {

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


      The bean in this next class appears to be the issue. If it's excluded then the application will boot without error.



      @Configuration
      @EnableWebSecurity
      public class MyConfig extends WebSecurityConfigurerAdapter {

      @Bean
      public CustomPropertyPlaceholderConfigurer propertyConfigurer(ApplicationContext context) {
      return new CustomPropertyPlaceholderConfigurer();
      }

      }


      Right now this CustomPropertyPlaceholderConfigurer class does nothing, I have some legacy classes that are similar, but in trying to troubleshoot this issue I eliminated everything else from my test application.



      public class CustomPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
      }


      I'm at a loss of what to try next. I've looked for details in Spring Security and Spring Boot about building a custom property placeholder configurer, but I didn't find anything useful.



      Versions: Spring Boot - 2.1.0.RELEASE | Spring Security - 5.1.1.RELEASE | JDK 1.8



      Also, I realize this app doesn't really do anything, there is a much larger application that has much more complicated logic, and this sample app here is just to replicate my issue to make it small for stackoverflow.










      share|improve this question















      I am building a Spring Boot application with Spring Security (spring-boot-starter-web and spring-boot-starter-security). I receive the following error from my application during boot:



          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
      at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:625) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:455) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
      ...


      My application class consists of the following:



      @SpringBootApplication
      public class CustomPropertiesApplication {

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


      The bean in this next class appears to be the issue. If it's excluded then the application will boot without error.



      @Configuration
      @EnableWebSecurity
      public class MyConfig extends WebSecurityConfigurerAdapter {

      @Bean
      public CustomPropertyPlaceholderConfigurer propertyConfigurer(ApplicationContext context) {
      return new CustomPropertyPlaceholderConfigurer();
      }

      }


      Right now this CustomPropertyPlaceholderConfigurer class does nothing, I have some legacy classes that are similar, but in trying to troubleshoot this issue I eliminated everything else from my test application.



      public class CustomPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
      }


      I'm at a loss of what to try next. I've looked for details in Spring Security and Spring Boot about building a custom property placeholder configurer, but I didn't find anything useful.



      Versions: Spring Boot - 2.1.0.RELEASE | Spring Security - 5.1.1.RELEASE | JDK 1.8



      Also, I realize this app doesn't really do anything, there is a much larger application that has much more complicated logic, and this sample app here is just to replicate my issue to make it small for stackoverflow.







      java spring spring-boot spring-security spring-web






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 20:06

























      asked Nov 9 at 19:37









      Josh Maag

      462312




      462312
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I see now that the answer was right in my output logs and I just failed to see it.



          o.s.c.a.ConfigurationClassEnhancer : @Bean method MyConfig.propertyConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.



          Adding static to my bean fixed the issue.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232259%2fspringsecurityfilterchain-objectpostprocessor-is-a-required-bean-exception%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I see now that the answer was right in my output logs and I just failed to see it.



            o.s.c.a.ConfigurationClassEnhancer : @Bean method MyConfig.propertyConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.



            Adding static to my bean fixed the issue.






            share|improve this answer

























              up vote
              0
              down vote













              I see now that the answer was right in my output logs and I just failed to see it.



              o.s.c.a.ConfigurationClassEnhancer : @Bean method MyConfig.propertyConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.



              Adding static to my bean fixed the issue.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                I see now that the answer was right in my output logs and I just failed to see it.



                o.s.c.a.ConfigurationClassEnhancer : @Bean method MyConfig.propertyConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.



                Adding static to my bean fixed the issue.






                share|improve this answer












                I see now that the answer was right in my output logs and I just failed to see it.



                o.s.c.a.ConfigurationClassEnhancer : @Bean method MyConfig.propertyConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.



                Adding static to my bean fixed the issue.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 21:09









                Josh Maag

                462312




                462312






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232259%2fspringsecurityfilterchain-objectpostprocessor-is-a-required-bean-exception%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Academy of Television Arts & Sciences

                    L'Équipe

                    1995 France bombings