Java 需要使用spring定义bean的帮助吗

Java 需要使用spring定义bean的帮助吗,java,spring,security,intellij-idea,Java,Spring,Security,Intellij Idea,我在网上搜索了解决方案,但没有找到任何解决方案。这是我最后的办法 2018-04-29 16:31:57.743警告71317---[主要]ConfigServletWebServerApplicationContext:在上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.unsatifiedPendencyException:创建名为“authorizationServerConfig”的bean时出错:通过字段“authenticat

我在网上搜索了解决方案,但没有找到任何解决方案。这是我最后的办法


2018-04-29 16:31:57.743警告71317---[主要]ConfigServletWebServerApplicationContext:在上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.unsatifiedPendencyException:创建名为“authorizationServerConfig”的bean时出错:通过字段“authenticationManager”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.unsatifiedpendencyException:创建名为“resourceServerConfig”的bean时出错:通过字段“authenticationManager”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.beanCurrentlyIncrementationException:创建名为“org.springframework.security.authenticationManager”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用

类别:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import 
org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends 
AuthorizationServerConfigurerAdapter {

@Autowired
private AuthenticationManager authenticationManager;

@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {

    security.tokenKeyAccess("permitAll()")
            .checkTokenAccess("isAuthenticated()");
}


@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients
            .inMemory()
            .withClient("ClientId")
            .secret("secret")
            .authorizedGrantTypes("authorization_code")
            .scopes("user_info")
            .autoApprove(true);
}


@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

    endpoints.authenticationManager(authenticationManager);
}
}
类别:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

@EnableResourceServer
@Configuration
public class ResourceServerConfig extends WebSecurityConfigurerAdapter {


@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private UserDetailsService customUserDetailsService;

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.requestMatchers()
            .antMatchers("/login", "/oauth/authorize")
            .and()
            .authorizeRequests()
            .anyRequest()
            .authenticated()
            .and()
            .formLogin()
            .permitAll();
}


@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {

    auth.parentAuthenticationManager(authenticationManager)
            .userDetailsService(customUserDetailsService);
}

@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

}

你看到这个了吗。您应该在
WebSecurityConfigurerAdapter
@Bedla中重写方法
authenticationManagerBean
,是的,我有。我尝试使用与建议完全相同的方法,但在尝试运行应用程序时出现以下错误:@Bedla org.springframework.beans.factory.unsatifiedDependencyException:创建名为“authorizationServerConfig”的bean时出错:通过字段“authenticationManager”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.unsatifiedpendencyException:创建名为“resourceServerConfig”的bean时出错:通过字段“authenticationManager”表示的未满足的依赖关系;嵌套异常isorg.springframework.beans.factory.BeanCurrentlyIncrementException:创建名为“org.springframework.security.authenticationManager”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用?