小编典典

java.lang.IllegalStateException:org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration上的错误处理条件

spring-boot

我正在尝试编写一个独立的可执行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文件中指定了属性。对于防爆应用-常见等。运行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

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

感谢帮助。

谢谢


阅读 864

收藏
2020-05-30

共1个答案

小编典典

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

2020-05-30