Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在上下文创建错误后,如何使用spring boot starter执行器完成spring boot应用程序?_Java_Spring_Spring Boot_Spring Boot Actuator - Fatal编程技术网

Java 在上下文创建错误后,如何使用spring boot starter执行器完成spring boot应用程序?

Java 在上下文创建错误后,如何使用spring boot starter执行器完成spring boot应用程序?,java,spring,spring-boot,spring-boot-actuator,Java,Spring,Spring Boot,Spring Boot Actuator,我有我的SpringBoot应用程序,它带有SpringBootStarterWeb和DataAccessConfig类来配置我的数据源。如果bean创建中出现一些错误(例如,数据源的密码错误),我会收到一个错误,java进程立即退出 然后我添加了SpringBootStarter执行器,它对我来说运行良好,并在信息和健康部分显示正确的数据。但现在,如果bean创建中出现一些错误(例如,数据源的密码错误),则不会创建spring上下文,但java进程仍然是活动的 我想找到一种方法,返回前面的fa

我有我的SpringBoot应用程序,它带有SpringBootStarterWeb和DataAccessConfig类来配置我的数据源。如果bean创建中出现一些错误(例如,数据源的密码错误),我会收到一个错误,java进程立即退出

然后我添加了SpringBootStarter执行器,它对我来说运行良好,并在信息和健康部分显示正确的数据。但现在,如果bean创建中出现一些错误(例如,数据源的密码错误),则不会创建spring上下文,但java进程仍然是活动的

我想找到一种方法,返回前面的fail fast逻辑,并在上下文创建出错后退出java进程

我的pom.xml内容

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
。。。
org.springframework.boot
spring启动程序父级
2.1.2.1发布
...
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧靴起动器执行器
org.springframework.boot
弹簧起动试验
测试
2.0.4.1发布
...
我的application.yml内容

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
my Application.java

@springboot应用程序
公共类应用程序扩展了SpringBootServletInitializer{
@凌驾
受保护的SpringApplicationBuilder配置(SpringApplicationBuilder应用程序){
返回应用程序.sources(application.class);
}
公共静态void main(字符串[]args){
SpringApplication.run(Application.class,args);
}
}
bean创建示例中的错误


2019-06-17 16:00:13.422 ERROR 18440 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$29a437a3]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getDataSource' defined in class path resource [ru/hflabs/cpc/DataAccessConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'getDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: ORA-01017: неверно имя пользователя/пароль; вход в систему запрещается

2019-06-17 16:00:13.447  INFO 18440 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-06-17 16:00:13.451  WARN 18440 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.Object.wait(Object.java:502)
 java.util.TimerThread.mainLoop(Timer.java:526)
 java.util.TimerThread.run(Timer.java:505)
2019-06-17 16:00:13.451  WARN 18440 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [oracle.jdbc.driver.BlockSource.ThreadedCachingBlockSource.BlockReleaser] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 oracle.jdbc.driver.BlockSource$ThreadedCachingBlockSource$BlockReleaser.run(BlockSource.java:329)
2019-06-17 16:00:13.451  WARN 18440 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [InterruptTimer] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.util.TimerThread.mainLoop(Timer.java:552)
 java.util.TimerThread.run(Timer.java:505)
2019-06-17 16:00:13.453  WARN 18440 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2019-06-17 16:00:13.465  INFO 18440 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-06-17 16:00:13.477 ERROR 18440 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) ~[spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at ru.hflabs.cpc.Application.main(Application.java:17) [classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:125) ~[spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:415) ~[spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) ~[spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) ~[spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    ... 8 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$29a437a3]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getDataSource' defined in class path resource [ru/hflabs/cpc/DataAccessConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'getDataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: ORA-01017: 


2019-06-17 16:00:13.422错误18440---[main]o.s.b.web.embedded.tomcat.TomcatStarter:启动tomcat上下文时出错。例外:org.springframework.beans.factory.BeanCreationException。消息:创建在类路径资源[org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]中定义的名为“servletendpointregister”的bean时出错:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.beanstantiationException:未能实例化[org.springframework.boot.actuate.endpoint.web.servletendpointregistrator]:工厂方法“servletendpointregistrator”引发异常;嵌套异常为org.springframework.beans.factory.unsatifiedDependencyException:创建名为“healthEndpoint”的bean时出错,该bean在类路径资源[org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]:通过方法“healthEndpoint”参数1表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“healthIndicatorRegistry”的bean时出错,该名称在类路径资源[org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.beanstantiationException:未能实例化[org.springframework.boot.actuate.health.HealthIndicatorRegistry]:工厂方法“HealthIndicatorRegistry”引发异常;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration”的bean时出错:通过构造函数实例化bean失败;嵌套异常为org.springframework.beans.beanstantiationException:未能实例化[org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$29a437a3]:构造函数引发异常;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“getDataSource”的bean时出错,该bean在类路径资源[ru/hflabs/cpc/DataAccessConfig.class]中定义:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.beanstantiationException:未能实例化[javax.sql.DataSource]:工厂方法“getDataSource”引发异常;嵌套异常为com.zaxxer.hikari.pool.HikariPool$PoolitizationException:未能初始化池:ORA-01017:;вход в систему запрещается
2019-06-17 16:00:13.447信息18440---[main]o.apache.catalina.core.StandardService:停止服务[Tomcat]
2019-06-17 16:00:13.451警告18440---[main]o.a.c.loader.WebappClassLoaderBase:web应用程序[ROOT]似乎已启动名为[Timer-0]的线程,但未能停止它。这很可能会造成内存泄漏。线程的堆栈跟踪:
java.lang.Object.wait(本机方法)
wait(Object.java:502)
mainLoop(Timer.java:526)
java.util.TimerThread.run(Timer.java:505)
2019-06-17 16:00:13.451警告18440---[main]o.a.c.loader.WebappClassLoaderBase:web应用程序[ROOT]似乎已启动名为[oracle.jdbc.driver.BlockSource.ThreadedCachingBlockSource.BlockReleaser]的线程,但未能停止它。这很可能会造成内存泄漏。线程的堆栈跟踪:
java.lang.Object.wait(本机方法)
BlockSource$ThreadedCachingBlockSource$BlockReleaser.run(BlockSource.java:329)
2019-06-17 16:00:13.451警告18440---[main]o.a.c.loader.WebappClassLoaderBase:web应用程序[ROOT]似乎已启动名为[InterruptTimer]的线程,但未能停止它。这很可能会造成内存泄漏。线程的堆栈跟踪:
java.lang.Object.wait(本机方法)
mainLoop(Timer.java:552)
java.util.TimerThread.run(Timer.java:505)
2019-06-17 16:00:13.453警告18440--[