【发布时间】:2018-03-26 12:51:42
【问题描述】:
直到今天我的应用程序运行良好,但突然出现了这个异常,我不知道该如何解决。
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.company.app.Application]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/core/userdetails/UserDetailsService.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:180) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
.....
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/security/core/userdetails/UserDetailsService.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:177) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:99) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:89) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3]
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:76) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3]
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:94) ~[spring-core-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:703) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getInterfaces(ConfigurationClassParser.java:886) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.processInterfaces(ConfigurationClassParser.java:373) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:321) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:190) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:293) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:166) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3]
... 43 common frames omitted
我评论了实现UserDetailsService 的类,但现在我有这个例外:
Caused by: java.lang.ClassNotFoundException: org.springframework.security.core.GrantedAuthority
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1269) ~[catalina.jar:9.0.0.M22]
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104) ~[catalina.jar:9.0.0.M22]
... 80 common frames omitted
Spring Security 依赖项似乎造成了一些麻烦。
我的 pom.xml(摘要):
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M3</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
我的实现(即使这不是问题):
@Service
public class CustomUserDetailsService implements UserDetailsService {
@Autowired
private SecurityService securityService;
@Override
public UserDetails loadUserByUsername( String username ) throws UsernameNotFoundException {
return new CustomUserDetails( securityService.findUserCredentialsByUsername( username ) );
}
}
编辑
这看起来很奇怪,因为我可以运行我的测试并且所有这些测试都从主类Application 加载上下文。测试不会失败,但是当我在 Tomcat 中运行应用程序时,它会失败!
有什么想法吗?谢谢
【问题讨论】:
标签: spring maven spring-boot spring-security spring-security-oauth2