&lt; <spring boot =“”1.1.6 =“”>&gt;线程“main”中的异常org.springframework.beans.factory.BeanDefinitionStoreException </spring>

时间:2014-09-18 11:52:58

标签: spring inversion-of-control spring-boot

我是初次启动并使用Spring启动1.1.6构建应用程序的新手。基本应用程序运行正常。

但是当我添加一些依赖项时,我无法启动应用程序并在启动时看到以下异常。

我的build.gradle文件

` buildscript {
    ext {

        springBootVersion = '1.1.6.RELEASE'
    }
    repositories {
        maven { 
        url "http://repo.spring.io/libs-snapshot" 
        }
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.6.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

sourceCompatibility = 1.7

compileJava {
    targetCompatibility = 1.7
}

war {
    baseName = 'gs-convert-jar-to-war'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    mavenLocal()
    maven { url "http://repo.spring.io/libs-snapshot" }
    maven { url "http://maven.springframework.org/milestone" }
}

dependencies {

    compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") {
        exclude module: "spring-boot-starter-tomcat"
        exclude module:"spring-boot-starter-logging"
    }
    providedRuntime("org.springframework.boot:spring-boot-starter-jetty:${springBootVersion}")

    compile("org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}")
    compile("org.springframework.boot:spring-boot-starter-aop:${springBootVersion}")
    compile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
    compile("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")

    compile("com.google.guava:guava:17.0")
    compile("com.squareup.retrofit:retrofit:1.6.0")
    compile("commons-io:commons-io:2.4")
    compile("com.local.abdd:abdd-jith912:1.0.4-SNAPSHOT"){
    exclude module:"slf4j-api"
    }
    compile("com.local.abdd:abdd-jith912:1.0.4-SNAPSHOT:tests"){
    exclude module:"slf4j-api"
    }
    testCompile("junit:junit")
    compile("org.slf4j:slf4j-api:1.7.7"){
    force = true
    }
    compile("org.slf4j:slf4j-log4j12:1.7.7"){
    force=true
    }
    compile("org.slf4j:slf4j-jdk14:1.7.7"){
    force=true
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}
`

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: ; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist
    at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:392)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:305)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:611)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
    at org.magnum.mobilecloud.video.Application.main(Application.java:27)
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
    at org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:50)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:82)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:77)
    at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:561)
    at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getSuperClass(ConfigurationClassParser.java:736)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:284)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:218)
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:435)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:258)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:218)
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:435)
    at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:389)
    ... 13 more

我的gradle依赖项输出太大,我无法进入此处。 但是我发现一些弹簧组件用作传递依赖,如

  |    +--- com.local.infra.thirdparty:oracle-simplefan:11.2.0.2
|    |         |    |    |    |    +--- javax.jms:jms:1.1
|    |         |    |    |    |    +--- org.springframework:spring-jms:3.1.1.RELEASE
|    |         |    |    |    |    |    +--- aopalliance:aopalliance:1.0
|    |         |    |    |    |    |    +--- org.springframework:spring-aop:3.1.1.RELEASE -> 4.0.7.RELEASE (*)
|    |         |    |    |    |    |    +--- org.springframework:spring-beans:3.1.1.RELEASE -> 4.0.7.RELEASE (*)
|    |         |    |    |    |    |    +--- org.springframework:spring-context:3.1.1.RELEASE -> 4.0.7.RELEASE (*)
|    |         |    |    |    |    |    +--- org.springframework:spring-core:3.1.1.RELEASE -> 4.0.7.RELEASE (*)
|    |         |    |    |    |    |    \--- org.springframework:spring-tx:3.1.1.RELEASE -> 3.2.2.RELEASE
|    |         |    |    |    |    |         +--- aopalliance:aopalliance:1.0
|    |         |    |    |    |    |         +--- org.springframework:spring-beans:3.2.2.RELEASE -> 4.0.7.RELEASE (*)
|    |         |    |    |    |    |         \--- org.springframework:spring-core:3.2.2.RELEASE -> 4.0.7.RELEASE (*)

 +--- org.springframework.security:spring-security-core:3.0.4.RELEASE -> 3.2.5.RELEASE (*)
|    |    |    |    |         |    |    +--- org.springframework.security:spring-security-taglibs:3.0.4.RELEASE
|    |    |    |    |         |    |    |    +--- org.springframework.security:spring-security-web:3.0.4.RELEASE -> 3.2.5.RELEASE (*)
|    |    |    |    |         |    |    |    +--- org.springframework.security:spring-security-acl:3.0.4.RELEASE
|    |    |    |    |         |    |    |    |    +--- org.springframework.security:spring-security-core:3.0.4.RELEASE -> 3.2.5.RELEASE (*)
|    |    |    |    |         |    |    |    |    \--- org.springframework:spring-context-support:3.0.3.RELEASE -> 3.2.2.RELEASE (*)
|    |    |    |    |         |    |    |    \--- org.springframework:spring-web:3.0.3.RELEASE -> 4.0.7.RELEASE (*)
|    |    |    |    |         |    |    +--- org.springframework.security:spring-security-config:3.0.4.RELEASE -> 3.2.5.RELEASE (*)

1 个答案:

答案 0 :(得分:2)

我并非100%确定这会解决您的问题,但它会将事情朝着正确的方向发展。

您有许多依赖项与同一Spring项目中的其他依赖项不同步。例如,Spring Framework依赖项中包含多个版本。大多数是4.0.7.RELEASE,但有一些是3.x.x。

解决此问题的一种方法是在有问题的模块上添加显式的直接依赖(Spring Boot将为您提供正确的版本。例如:

dependencies {
    compile 'org.springframework:spring-context-support'
    compile 'org.springframework:spring-jms'
    compile 'org.springframework:spring-tx'
    compile 'org.springframework:spring-security-acl'
    compile 'org.springframework:spring-security-taglibs'
}

尝试进行此更改并再次查看gradle dependencies的输出。如果您发现任何其他模块的版本与同一Spring项目中的其他模块不一致,请重复此过程。一旦版本看起来都正确,请尝试再次运行您的应用。