【问题标题】:java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfigurationjava.lang.IllegalStateException: org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration 上的错误处理条件
【发布时间】:2015-12-21 20:36:48
【问题描述】:

我正在尝试编写一个独立的可执行 jar (fat jar)。我正在使用 spring boot gradle 插件并编写一个 SpringBoot App 来执行此操作。

这是我的 Application.java 文件

@Configuration
@EnableAutoConfiguration
@EnableRabbit
@EntityScan("persistence.domain")
@EnableJpaRepositories("persistence.repository")
@ComponentScan(basePackages = {"common","service"})
public class Application {

     public static void main(final String[] args) {
            final SpringApplicationBuilder appBuilder = new SpringApplicationBuilder(
                Application.class);
            appBuilder.profiles("common", "common_db").run(args);
          }

      @Bean
      @Primary
      @ConfigurationProperties(prefix = "spring.datasource")
      public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
      }
}

我在 yml 文件中指定了属性。对于 ex application-common 等。运行 Application.java 时出现错误:

[2015-09-24 14:40:22.304] boot - 32791  INFO [main] ---AnnotationConfigEmbeddedWebApplicationContext: Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@51a282af: startup date [Thu Sep 24 14:40:22 IST 2015]; root of context hierarchy
[2015-09-24 14:40:23.194] boot - 32791  WARN [main] --- AnnotationConfigEmbeddedWebApplicationContext: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: ; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
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.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)
at storm.Application.main(Application.java:28)
Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:58)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:92)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:190)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:435)
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:389)
... 12 more
Caused by: java.lang.NullPointerException
at org.springframework.boot.autoconfigure.condition.OnPropertyCondition.getMatchOutcome(OnPropertyCondition.java:61)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45)
... 16 more

这是我的 build.gradle

def projects= [
    ":common",
    ":persistence",
    ":adapter"

]

buildscript {
repositories {
  mavenCentral()
  maven { url 'http://repo.spring.io/snapshot' }
  maven { url 'http://repo.spring.io/milestone' }
}
dependencies { classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: springBootVersion }

}

apply plugin: 'spring-boot'
apply plugin: 'maven-publish'
apply from: "${rootDir}/deployTasks.gradle"

springBoot {
mainClass = "storm.Application"
}

dependencies {
    compile project(':common')
    compile project(':adapter')
    compile project(':persistence')
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.1.8.RELEASE'
    compile group : 'org.springframework.boot',name: 'spring-boot-autoconfigure', version : '1.1.8.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.1.8.RELEASE'

}

application-common_db.yml 中的数据库规范

database:
host: localhost
port: 3306
schema: subscriptions
username: root
password: root
autoconnect:
maxReconnects: 3
initialTimeout: 2
timeout:
connectTimeout: 0
socketTimeout: 0
failover:
host: localhost 
port: 3306
queriesBeforeRetryMaster: 50
secondsBeforeRetryMaster: 30


spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://${database.host}:${database.port},${database.failover.host}:${database.failover.port}/${database.schema}?${database.properties}
username: ${database.username}
password: ${database.password}
continueOnError: true
initialize: false
initialSize: 0
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 5000
removeAbandonedTimeout: 60
removeAbandoned: true
minIdle: 0

我不确定如何解决此错误。任何人都可以建议这里出了什么问题,为什么我会得到 nullPointerException。

感谢您的帮助。

谢谢

【问题讨论】:

标签: spring gradle spring-boot build.gradle


【解决方案1】:

这是由不匹配的 Spring Boot 依赖项引起的。 检查您的类路径以查找有问题的资源。您已明确包含版本 1.1.8.RELEASE,但您还包含了 3 个其他项目。那些可能包含不同的 Spring Boot 版本,导致此错误。

【讨论】:

  • 我检查了所有项目的依赖关系,所有项目都使用相同的版本 (1.1.8.Release)。这并没有为我解决问题:((((
  • 我们需要比较的不仅仅是您明确定义的依赖项(您刚刚发布的内容),还有真正添加到您的 jar 文件中的 jar 文件。这也将包括传递依赖,可能包含带有违规版本控制的 jar。打开您的 jar 文件并发布一个 jar 列表,例如:spring-data-jpa-1.1.8.jar 等。顺便说一句,我会在一小时内回来。
  • 哦,Gergely,它成功了。当我看到引用库列表时,我可以看到 2.1.6 和 1.1.8 的 jars。从路径中删除 2.1.6 对我来说是诀窍:)。非常感谢您在这里帮助我:)。欣赏它:)
  • 嗯,这是一个很长的镜头,但有人可以更好地解释一下您如何准确地看到 jar 文件并从路径中删除有问题的版本吗?
  • @jimboweb 这取决于你使用什么依赖管理系统。如果是 maven,那么:打开“有效 pom”会显示完整的依赖列表。搜索/grep 查找有问题的资源。 (或者如果您正在生成它,请查看您的 lib 文件夹)。删除它是通过 pom 的依赖管理部分中的排除标记完成的。
【解决方案2】:

此错误是由于多个项目具有违规资源。

尝试以另一种方式添加依赖项项目。 (例如在 pom.xml 或外部依赖项中)

【讨论】:

    【解决方案3】:

    在我的例子中,我从 SB Initializer 创建了一个 SB 应用程序,并在其中包含了相当数量的 deps 用于其他事情。我进去并在 build.gradle 文件中注释掉了它们的引用,所以留下了:

    implementation 'org.springframework.boot:spring-boot-starter-hateoas'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'org.hsqldb:hsqldb'
    runtimeOnly 'org.postgresql:postgresql'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
    

    作为部门。然后我的准系统 SB 应用程序能够成功构建并运行。当我尝试做可能需要那些被注释掉的库的事情时,我会将它们添加回来,看看有什么问题。

    【讨论】:

      【解决方案4】:

      我知道这是一个很老的问题,但我遇到了类似的问题并以不同的方式解决了它。执行器自动配置 pom 不知何故无效,因此抛出了 IllegalStateException。我从我的 maven 存储库中删除了 actuator* 依赖项,并在 eclipse 中进行了 Maven 更新,然后下载了正确/有效的依赖项并解决了我的问题。

      【讨论】:

        【解决方案5】:

        由于版本不兼容检查版本或使用弹簧启动时删除版本,我有相同的它

        【讨论】:

          猜你喜欢
          • 2020-06-30
          • 2020-06-27
          • 2019-01-06
          • 1970-01-01
          • 1970-01-01
          • 2020-08-19
          • 2015-04-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多