Can not apply DaoAuthenticationConfigurer to already built object

前端 未结 1 765
梦谈多话
梦谈多话 2021-01-12 01:17

I\'m getting this exception:

[WARN] org.springframework.web.context.support.GenericWebApplicationContext - Exception encountered during context initializatio         


        
相关标签:
1条回答
  • 2021-01-12 01:41

    It took me two days, but I believe I've finally solved this. In my SecurityConfiguration class I had the following method:

    @Configuration
    @EnableWebMvcSecurity
    @EnableGlobalMethodSecurity(jsr250Enabled=true, prePostEnabled=true)
    public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    
        @Autowired
        public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(authenticationService);
        }
    
    }
    

    I replaced the configureGlobal method with a configure method:

        @Override
        public void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(authenticationService);
        }
    

    And now everything works fine.

    According to this answer the difference is that the using configureGlobal will allow the AuthenticationManager by global method security or another HttpSecurity (WebSecurityConfigurerAdapter).

    As you can see above, I am enabling both Web Mvc Security and global method security. According to my unit tests, both continue to work with this change, but there is some debate here at my office on whether this change is correct (ie, if it is configuring global method security correctly), or if there is another problem with this solution.

    We believe the root cause of the problem is some type of Spring bug, possibly a race condition. As unlikely as that seems, the problem only manifested itself when we added a empty class to the project, it didn't matter what the class's package or name was.

    0 讨论(0)
提交回复
热议问题