以下工作正常
@Configuration
@EnableCaching
@EnableOAuth2Sso
@EnableWebSecurity
@EnableOAuth2Client
@SpringBootApplication
@Import({ AppConvConfig.class, AppPropConfig.class, AppSecConfig.class })
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableTransactionManagement(proxyTargetClass = true)
@EntityScan(basePackages = { BeanConstants.SCAN_PKG_JDBC_ENTITY })
@EnableJpaRepositories(basePackages = { BeanConstants.SCAN_PKG_JDBC_REPO })
@ComponentScan(basePackages = { BeanConstants.SCAN_PKG_SERVI, BeanConstants.SCAN_PKG_FLICK_WEB })
public class AppConfig extends WebMvcConfigurerAdapter {
..
}
但如果我在上面添加@EnableAuthorizationServer
,请在启动时开始看到以下异常
***************************
APPLICATION FAILED TO START
***************************
Description:
Method springSecurityFilterChain in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration required a single bean, but 2 were found:
- remoteTokenServices: defined by method 'remoteTokenServices' in org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$RemoteTokenServicesConfiguration$TokenInfoServicesConfiguration
- defaultAuthorizationServerTokenServices: defined by method 'defaultAuthorizationServerTokenServices' in org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
答案 0 :(得分:0)
没关系,@EnableOAuth2Sso
& @EnableOAuth2Client
是多余的,已移除@EnableOAuth2Sso
并且启动正常。测试其余部分。最终名单:
@Configuration
@EnableCaching
@EnableWebSecurity
@EnableOAuth2Client
@EnableAuthorizationServer
@SpringBootApplication
@Import({ AppConvConfig.class, AppPropConfig.class, AppSecConfig.class })
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableTransactionManagement(proxyTargetClass = true)
@EntityScan(basePackages = { BeanConstants.SCAN_PKG_JDBC_ENTITY })
@EnableJpaRepositories(basePackages = { BeanConstants.SCAN_PKG_JDBC_REPO })
@ComponentScan(basePackages = { BeanConstants.SCAN_PKG_SERVI, BeanConstants.SCAN_PKG_FLICK_WEB })