当前位置: 首页 > 面试题库 >

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

莘聪
2023-03-14
问题内容

我正在尝试编写一个独立的可执行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。

感谢帮助。

谢谢


问题答案:

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



 类似资料:
  • 我是Flink的新手,已经通过网站/示例/博客开始学习。我正在努力正确使用操作符。基本上我有两个问题 问题1:Flink是否支持声明性异常处理,我需要处理解析/验证/。。。错误? 我可以使用组织吗。阿帕奇。Flink。运行时。操作员。分类ExceptionHandler或类似的程序来处理错误 还是Rich/FlatMap功能是我的最佳选择?如果Rich/FlatMap是唯一的选项,那么是否有办法在

  • 错误处理 有些方法通通过参数返回 error 的引用,使用这样的方法时应当检查方法的返回值,而非 error 的引用。 推荐: NSError *error = nil; if (![self trySomethingWithError:&error]) { // Handle Error } 此外,一些苹果的 API 在成功的情况下会对 error 参数(如果它非 NULL)写入垃圾值(

  • 问题内容: 我有一个PHP表单,可将​​数据输入到我的MySQL数据库中。我的主键是用户输入的值之一。当用户输入表中已经存在的值时,将返回MySQL错误“键1的重复项’输入值’。我想提醒用户他们需要输入一个不同的值,而不是该错误。只是回音或其他内容。我想我的问题归结为:如何将特定的MySQL错误转换为PHP消息谢谢 编辑:下面尼克的答案是不错的,但是有什么办法可以区分特定的错误? 问题答案: 要检

  • 本文向大家介绍PHP 处理文件上传错误,包括了PHP 处理文件上传错误的使用技巧和注意事项,需要的朋友参考一下 示例 该$_FILES["FILE_NAME"]['error'](其中"FILE_NAME"是文件输入,存在于你的表单的名称属性的值)可能包含以下值之一: UPLOAD_ERR_OK -没有错误,文件上传成功。 UPLOAD_ERR_INI_SIZE-上载的档案超过中的upload_m

  • 通过对错误类型实现 Display 和 From,我们能够利用上绝大部分标准库错误处理工具。然而,我们遗漏了一个功能:轻松 Box 我们错误类型的能力。 标准库会自动通过 Form 将任意实现了 Error trait 的类型转换成 trait 对象 Box<Error> 的类型(原文:The std library automatically converts any type that imp

  • 错误处理(error handling)是处理可能发生失败情况的过程。例如读取一个文件失败,然后继续使用这个失效的输入显然是有问题的。错误处理允许我们以一种显式的方式来发现并处理这类错误,避免了其余代码发生潜在的问题。 有关错误处理的更多内容,可参考官方文档的错误处理的章节。

  • 处理一个 RESTful API 请求时, 如果有一个用户请求错误或服务器发生意外时, 你可以简单地抛出一个异常来通知用户出错了。 如果你能找出错误的原因 (例如,所请求的资源不存在),你应该 考虑抛出一个适当的HTTP状态代码的异常 (例如, yii\web\NotFoundHttpException意味着一个404 HTTP状态代码)。 Yii 将通过HTTP状态码和文本发送相应的响应。 它还

  • Yii 内置了一个error handler错误处理器,它使错误处理更方便, Yii错误处理器做以下工作来提升错误处理效果: 所有非致命PHP错误(如,警告,提示)会转换成可获取异常; 异常和致命的PHP错误会被显示, 在调试模式会显示详细的函数调用栈和源代码行数。 支持使用专用的 控制器操作 来显示错误; 支持不同的错误响应格式; error handler 错误处理器默认启用, 可通过在应用的