java.lang.ClassNotFoundException:com.stormpath.sdk.schema.Schema 在 Spring 启动

java.lang.ClassNotFoundException: com.stormpath.sdk.schema.Schema at Spring Boot start

我正在尝试创建一个 Spring 引导应用程序,它使用 Stormpath API.

作为用户管理

这里是 Gradle 依赖块:

dependencies {
  compile 'org.springframework.boot:spring-boot-starter-web'

  compile 'org.springframework.boot:spring-boot-starter-data-jpa:' + springBootVersion

  compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: springBootVersion

  compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: springBootVersion

  compile group: 'com.stormpath.spring', name: 'stormpath-default-spring-boot-starter', version: stormpathVersion

  compile 'org.projectlombok:lombok:1.16.10'

  compile 'org.springframework.boot:spring-boot-starter-thymeleaf:' + springBootVersion

  compile 'org.yaml:snakeyaml'

  compile 'org.hsqldb:hsqldb:2.0.0'

  compile 'com.stormpath.sdk:stormpath-sdk-api:1.1.1'

  compile group: 'com.stormpath.sdk', name: 'stormpath-sdk-httpclient', version: '1.1.1'

  testCompile 'org.springframework.boot:spring-boot-starter-test'

  testCompile 'junit:junit'

}

这里是启用 Spring 安全性的 Stormpath 配置:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .apply(stormpath())
            .and()
            .authorizeRequests()
                .antMatchers("/", "/public").permitAll();
    }
}

在这种状态下,使用 stormpath.client.cacheManager.enabled: false,它给了我:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.stormpath.sdk.servlet.filter.FilterChainManager]: Factory method 'stormpathFilterChainManager' threw exception; nested exception is java.lang.NoClassDefFoundError: com/stormpath/sdk/schema/Schema
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 71 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/stormpath/sdk/schema/Schema
at com.stormpath.sdk.impl.directory.DefaultDirectory.<clinit>(DefaultDirectory.java:71) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_111]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_111]
at com.stormpath.sdk.lang.Classes.instantiate(Classes.java:188) ~[stormpath-sdk-api-1.1.1.jar:1.1.1]
at com.stormpath.sdk.impl.ds.DefaultResourceFactory.instantiate(DefaultResourceFactory.java:65) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.SubtypeDispatchingResourceFactory.instantiate(SubtypeDispatchingResourceFactory.java:80) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultDataStore.instantiate(DefaultDataStore.java:216) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultDataStore.getResource(DefaultDataStore.java:249) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultDataStore.getResource(DefaultDataStore.java:236) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.application.AbstractAccountStoreMapping.getAccountStore(AbstractAccountStoreMapping.java:55) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.application.DefaultApplication.getDefaultAccountStore(DefaultApplication.java:475) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.servlet.config.RegisterEnabledPredicate.test(RegisterEnabledPredicate.java:23) ~[stormpath-sdk-servlet-1.1.4.jar:1.1.4]
at com.stormpath.sdk.servlet.config.RegisterEnabledPredicate.test(RegisterEnabledPredicate.java:11) ~[stormpath-sdk-servlet-1.1.4.jar:1.1.4]
at com.stormpath.spring.config.AbstractStormpathWebMvcConfiguration.addRoutes(AbstractStormpathWebMvcConfiguration.java:464) ~[stormpath-spring-webmvc-1.1.4.jar:1.1.4]
at com.stormpath.spring.config.AbstractStormpathWebMvcConfiguration.stormpathFilterChainManager(AbstractStormpathWebMvcConfiguration.java:1357) ~[stormpath-spring-webmvc-1.1.4.jar:1.1.4]
at com.stormpath.spring.boot.autoconfigure.StormpathWebMvcAutoConfiguration.stormpathFilterChainManager(StormpathWebMvcAutoConfiguration.java:564) ~[stormpath-webmvc-spring-boot-starter-1.1.4.jar:1.1.4]
at com.stormpath.spring.boot.autoconfigure.StormpathWebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f4e52d73.CGLIB$stormpathFilterChainManager(<generated>) ~[stormpath-webmvc-spring-boot-starter-1.1.4.jar:1.1.4]
at com.stormpath.spring.boot.autoconfigure.StormpathWebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f4e52d73$$FastClassBySpringCGLIB$$de2b4e13.invoke(<generated>) ~[stormpath-webmvc-spring-boot-starter-1.1.4.jar:1.1.4]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at com.stormpath.spring.boot.autoconfigure.StormpathWebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f4e52d73.stormpathFilterChainManager(<generated>) ~[stormpath-webmvc-spring-boot-starter-1.1.4.jar:1.1.4]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 72 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.stormpath.sdk.schema.Schema
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]

如果我设置 cacheManager.enabled: true 错误变为:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.stormpath.sdk.application.Application]: Factory method 'stormpathApplication' threw exception; nested exception is java.lang.NoClassDefFoundError: com/stormpath/sdk/account/EmailVerificationStatus
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 48 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/stormpath/sdk/account/EmailVerificationStatus
at com.stormpath.sdk.impl.account.DefaultAccount.<clinit>(DefaultAccount.java:68) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.cache.WriteCacheFilter.cache(WriteCacheFilter.java:282) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.cache.WriteCacheFilter.filter(WriteCacheFilter.java:69) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.cache.ReadCacheFilter.filter(ReadCacheFilter.java:66) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.api.DecryptApiKeySecretFilter.filter(DecryptApiKeySecretFilter.java:63) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.EnlistmentFilter.filter(EnlistmentFilter.java:42) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultFilterChain.filter(DefaultFilterChain.java:52) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultDataStore.getResourceData(DefaultDataStore.java:333) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultDataStore.getResource(DefaultDataStore.java:248) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.ds.DefaultDataStore.getResource(DefaultDataStore.java:236) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.client.DefaultClient.getCurrentTenant(DefaultClient.java:111) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.sdk.impl.client.DefaultClient.getApplications(DefaultClient.java:228) ~[stormpath-sdk-impl-1.1.4.jar:1.1.4]
at com.stormpath.spring.config.AbstractStormpathConfiguration.stormpathApplication(AbstractStormpathConfiguration.java:134) ~[stormpath-spring-1.1.4.jar:1.1.4]
at com.stormpath.spring.boot.autoconfigure.StormpathAutoConfiguration.stormpathApplication(StormpathAutoConfiguration.java:44) ~[stormpath-spring-boot-starter-1.1.4.jar:1.1.4]
at com.stormpath.spring.boot.autoconfigure.StormpathAutoConfiguration$$EnhancerBySpringCGLIB$b9aeaeb.CGLIB$stormpathApplication[=16=](<generated>) ~[stormpath-spring-boot-starter-1.1.4.jar:1.1.4]
at com.stormpath.spring.boot.autoconfigure.StormpathAutoConfiguration$$EnhancerBySpringCGLIB$b9aeaeb$$FastClassBySpringCGLIB$955372.invoke(<generated>) ~[stormpath-spring-boot-starter-1.1.4.jar:1.1.4]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at com.stormpath.spring.boot.autoconfigure.StormpathAutoConfiguration$$EnhancerBySpringCGLIB$b9aeaeb.stormpathApplication(<generated>) ~[stormpath-spring-boot-starter-1.1.4.jar:1.1.4]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 49 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.stormpath.sdk.account.EmailVerificationStatus
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]

我正在关注他们官方页面上的教程:official page

更新: 下面的未知主机问题与这个问题无关 ">>此外,在随机开始时,它告诉我 api.stormpath.com 是一个未知主机。但我认为这是一个单独的问题。<<"

欢迎任何建议。谢谢!

您正在使用 stormpath-sdk-api:1.1.1stormpath-sdk-impl:1.1.4

stormpath-sdk-api:1.1.1 and stormpath-sdk-api:1.1.2 不包含缺失的 类.

您可以在 1.1.4 中找到丢失的 类。 EmailVerificationStatus and Schema

请改用 1.1.4 版。

根据教程,使用最新的稳定版 stormpath-default-spring-boot-starter,即撰写本文时的版本 1.1.4。此外,您不需要包含以下依赖项:

compile 'com.stormpath.sdk:stormpath-sdk-api'
compile group: 'com.stormpath.sdk', name: 'stormpath-sdk-httpclient'

引用stormpath-default-spring-boot-starter时会自动包含这两个。