title: spring-security, java-config: IllegalArgumentException: An AuthenticationManager is required
body: <p>Cannot get security config right. Suspect current stumbling block is @EnableGlobalMethodSecurity. </p>
  
  <p>Getting the following exception at init:</p>
  
  <pre><code>DEBUG 2020-01-12 20:57:12,474 [RMI TCP Connection(3)-127.0.0.1] o.s.s.c.a.a.b.AuthenticationManagerBuilder - No authenticationProviders and no parentAuthenticationManager defined. Returning null.
  
  ...
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: An AuthenticationManager is required
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) ~[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5014) ~[catalina.jar:7.0.62]
  
  Caused by: java.lang.IllegalArgumentException: An AuthenticationManager is required
      at org.springframework.util.Assert.notNull(Assert.java:112) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.security.access.intercept.AbstractSecurityInterceptor.afterPropertiesSet(AbstractSecurityInterceptor.java:131) ~[spring-security-core-4.0.0.RELEASE.jar:?]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      ... 59 more
  </code></pre>
  
  <p>Relevant files (imports, irrelevant methods reducted):</p>
  
  <p>WebAppInitializer.java</p>
  
  <pre><code>package com.foo.app.spring;
  
  public class WebAppInitializer extends AbstractDispatcherServletInitializer {
  
      @Override
      protected WebApplicationContext createRootApplicationContext() {
          final AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
          appContext.register(RootConfig.class, SecurityConfig.class);
          return appContext;
      }
  
      @Override
      protected WebApplicationContext createServletApplicationContext() {
          final AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
          appContext.register(WebConfig.class);
          return appContext;
      }
  }
  </code></pre>
  
  <p>SecurityWebAppInitializer.java:</p>
  
  <pre><code>package com.foo.app.spring;
  
  public class SecurityWebAppInitializer extends AbstractSecurityWebApplicationInitializer {}
  </code></pre>
  
  <p><code>RootConfig</code> contains services, repositories, all business logic layer. <code>WebConfig</code> holds controllers, plus other mvc odds and ends.</p>
  
  <p>SecurityConfig.java:</p>
  
  <pre><code>package com.foo.app.spring;
  
  @Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true)
  @ComponentScan("com.foo.app.security")
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private MyUserDetailsService myUserDetailsService;
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(myUserDetailsService).passwordEncoder(passwordEncoder());
      }
  }
  </code></pre>
  
  <p><code>GlobalMethodSecurityConfiguration#authenticationManager</code> returns null.</p>
  
  <p>Would appreciate assistance. Thanks!</p>