Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将DaoAuthenticationConfigurer应用于已生成的对象_Java_Spring_Spring Security_Jhipster_Codeship - Fatal编程技术网

Java 无法将DaoAuthenticationConfigurer应用于已生成的对象

Java 无法将DaoAuthenticationConfigurer应用于已生成的对象,java,spring,spring-security,jhipster,codeship,Java,Spring,Spring Security,Jhipster,Codeship,我得到一个例外: [WARN] org.springframework.web.context.support.GenericWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with

我得到一个例外:

[WARN] org.springframework.web.context.support.GenericWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountResource': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private io.ilopezluna.japanathome.service.UserService io.ilopezluna.japanathome.web.rest.AccountResource.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.crypto.password.PasswordEncoder io.ilopezluna.japanathome.service.UserService.passwordEncoder; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: Cannot apply org.springframework.security.config.annotation.authentication.configurers.userdetails.DaoAuthenticationConfigurer@54aa5730 to already built object
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:293) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
你可以在网上看到更多


此异常在我执行测试期间引发。但我无法在本地主机上复制它,我总是获得构建成功:这花了我两天时间,但我相信我终于解决了这个问题。在我的
SecurityConfiguration
类中,我有以下方法:

@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(jsr250Enabled=true, prePostEnabled=true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(authenticationService);
    }

}
我将
configureGlobal
方法替换为
configure
方法:

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(authenticationService);
    }
现在一切都很好

根据区别,使用
configureGlobal
将允许
AuthenticationManager
通过全局方法安全性或另一个HttpSecurity(websecurityconfigureadapter)

正如您在上面看到的,我同时启用了Web Mvc安全性和全局方法安全性。根据我的单元测试,两者都继续使用此更改,但在我的办公室中,关于此更改是否正确(即,是否正确配置了全局方法安全性)或此解决方案是否存在其他问题,存在一些争论


我们认为问题的根本原因是某种类型的Spring bug,可能是竞争条件。虽然看起来不太可能,但问题只在我们向项目中添加了一个空类时才显现出来,不管该类的包或名称是什么。

Ups,抱歉,已更新!您是否将任何配置存储为静态属性?我们是否可以查看
SecurityConfiguration.configureGlobal
?在单元测试中,Spring的上下文管理背后有一个漏洞,所以这可能会被破坏!这里您可以看到您提到的方法:这里您可以看到我的静态数据:如果它在您的机器上工作,但在Travis上不工作,那么可能是JDK的问题?您在这两个版本上使用的是相同的版本吗?您可能遇到了循环bean引用,当BeanPostProcessors使用(方法安全性)时,循环bean引用处理得不是很好。如果您有一个复制此问题的示例,我建议您在使用Boot时报告一个错误,如果是,则可能与@RobWinch有关-看起来SEC-2661就是问题所在,谢谢!SEC-2661提到“所有的
@Autowired
需要解决”是我的问题的关键。“谢谢,”罗布温奇说。