Java 带Gradle的spring引导安全oauth 2不工作无法处理配置类的导入候选项
我正在尝试创建一个基于Gradle的spring boot安全项目,该项目实现OAUTH 2。我已附加build.gradle文件和authorizationServerConfig文件,该文件在启动服务时失败 Build.gradle:Java 带Gradle的spring引导安全oauth 2不工作无法处理配置类的导入候选项,java,spring-boot,gradle,oauth-2.0,Java,Spring Boot,Gradle,Oauth 2.0,我正在尝试创建一个基于Gradle的spring boot安全项目,该项目实现OAUTH 2。我已附加build.gradle文件和authorizationServerConfig文件,该文件在启动服务时失败 Build.gradle: buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:sprin
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE")
}
}
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'oauth2-example-SB'
version = '0.0.1'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa:2.0.3.RELEASE')
compile('org.springframework.boot:spring-boot-starter-security:2.0.3.RELEASE')
compile('org.springframework.security.oauth:spring-security-oauth2:2.0.3.RELEASE')
compile('mysql:mysql-connector-java:8.0.13')
compile('commons-dbcp:commons-dbcp:1.4')
compile('org.projectlombok:lombok:1.16.20')
testCompile('junit:junit')
}
授权服务器配置
@Configuration
@EnableAuthorizationServer
public class AuthorisationServerConfig extends AuthorizationServerConfigurerAdapter{
static final String CLIEN_ID = "techares-client";
static final String GRANT_TYPE = "password";
static final String CLIENT_SECRET = "$2a$04$e/c1/RfsWuThaWFCrcCuJeoyvwCV0URN/6Pn9ZFlrtIWaU/vj/BfG";
static final String AUTHORIZATION_CODE = "authorization_code";
static final String REFRESH_TOKEN = "refresh_token";
static final String IMPLICIT = "implicit";
static final String SCOPE_READ = "read";
static final String SCOPE_WRITE = "write";
static final String TRUST = "trust";
static final int ACCESS_TOKEN_VALIDITY_SECONDS = 1*60*60;
static final int FREFRESH_TOKEN_VALIDITY_SECONDS = 6*60*60;
@Autowired
private TokenStore tokenStore;
@Autowired
private AuthenticationManager authenticationManager;
@Override
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
configurer
.inMemory()
.withClient(CLIEN_ID)
.secret(CLIENT_SECRET)
.authorizedGrantTypes(GRANT_TYPE, AUTHORIZATION_CODE, REFRESH_TOKEN, IMPLICIT )
.scopes(SCOPE_READ, SCOPE_WRITE, TRUST)
.accessTokenValiditySeconds(ACCESS_TOKEN_VALIDITY_SECONDS).
refreshTokenValiditySeconds(FREFRESH_TOKEN_VALIDITY_SECONDS);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore)
.authenticationManager(authenticationManager);
}
}
我正在尝试启动spring启动应用程序,但遇到以下异常
2019-06-30 08:42:42.079信息26356---[main]com.spring.main应用程序:在Ares-MacBook-Pro.local上用PID 26356启动main应用程序(/eclipse workspace/ds_alg/oauth2 example SB/bin/main由arun在/eclipse workspace/ds_alg/oauth2 example SB中启动)
2019-06-30 08:42:42.081信息26356---[main]com.spring.main应用程序:未设置活动配置文件,返回默认配置文件:默认
2019-06-30 08:42:42.123信息26356---[main]配置ServletWebServerApplicationContext:刷新org.springframework.boot.web.servlet.context。AnnotationConfigServletWebServerApplicationContext@618b19ad:启动日期[Sun Jun 30 08:42:42 IST 2019];上下文层次结构的根
2019-06-30 08:42:42.243警告26356---[main]ConfigServletWebServerApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanDefinitionStoreException:无法处理配置类的导入候选项[com.spring.configuration.authorizationServerConfig];嵌套异常为java.io.FileNotFoundException:无法打开类路径资源[org/springframework/security/config/annotation/authentication/configurers/globalaauthenticationConfigureRadapter.class],因为它不存在
2019-06-30 08:42:42.497错误26356---[main]o.s.boot.SpringApplication:应用程序运行失败
org.springframework.beans.factory.BeanDefinitionStoreException:无法处理配置类[com.spring.configuration.authorizationServerConfig]的导入候选项;嵌套异常为java.io.FileNotFoundException:类路径资源无法打开[org/springframework/security/config/annotation/authentication/configurers/globalaauthenticationconfigureradapter.class],因为它不存在
在org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:648)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:303)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:194)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:202)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:170)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.annotation.ConfigurationClassPostProcessor.PostProcessBeandDefinitionRegistry(ConfigurationClassPostProcessor.java:233)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.support.postprocessorregistrationlegate.invokeBeanDefinitionRegistryPostProcessors(postprocessorregistrationlegate.java:273)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.support.postprocessorregistrationlegate.invokeBeanFactoryPostProcessors(postprocessorregistrationlegate.java:93)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:327)~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
在com.spring.MainApplication.main(MainApplication.java:10)~[main/:na]
原因:java.io.FileNotFoundException:类路径资源[org/springframework/security/config/annotation/authentication/configurers/GlobalAuth]