我试图创建一个基于Gradle的实现OAUTH 2的Spring Boot安全项目。我已经附加了build.gradle文件和AuthorisationServerConfig文件,它们在启动服务时失败。
Build.gradle:
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')
}
AuthorisationServerConfig
@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 Boot应用程序,但出现以下异常。
2019-06-30 08:42:42.079 INFO 26356 --- [main] com.spring.MainApplication:使用PID 26356(/ eclipse-workspace / ds_alg / oauth2-在Ares-MacBook-Pro.local上启动MainApplication example-SB / bin / main由arun在/ eclipse-workspace / ds_alg / oauth2-example-SB中启动) 2019-06-30 08:42:42.081信息26356 --- [main] com.spring.MainApplication:未设置活动配置文件,回退到默认配置文件:默认 2019-06-30 08:42:42.123 INFO 26356 --- [main] ConfigServletWebServerApplicationContext:刷新org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@618b19ad:启动日期[Sun Jun 30 08:42:42 IST 2019 ];上下文层次结构的根 2019-06-30 08:42:42.243 WARN 26356 --- [main] ConfigServletWebServerApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanDefinitionStoreException:无法为配置类[com处理导入候选对象.spring.configuration.AuthorisationServerConfig];嵌套异常为java.io.FileNotFoundException:类路径资源[org / springframework / security / config / annotation / authentication / configurers / GlobalAuthenticationConfigurerAdapter.class]无法打开,因为它不存在 2019-06-30 08:42:42.497错误26356 --- [main] o.s.boot.SpringApplication:应用程序运行失败
org.springframework.beans.factory.BeanDefinitionStoreException:无法处理配置类[com.spring.configuration.AuthorisationServerConfig]的导入候选对象;嵌套异常为java.io.FileNotFoundException:类路径资源[org / springframework / security / config / annotation / authentication / configurers / GlobalAuthenticationConfigurerAdapter.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.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.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 / GlobalAuthenticationConfigurerAdapter.class]无法打开,因为它不存在 在org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)〜[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.core.type.classreading.SimpleMetadataReader。(SimpleMetadataReader.java:51)〜[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)〜[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:88)〜[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] 在org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:75)〜[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] 在org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81)〜[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:734)〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.context.annotation.ConfigurationClassParser $ SourceClass.getSuperClass(ConfigurationClassParser.java:950)〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:333)〜[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.processMemberClasses(ConfigurationClassParser.java:362)〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:265)〜[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.processImports(ConfigurationClassParser.java:638)〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE
请提出一些解决问题的想法,