<tfoot id='7t9GD'></tfoot>
<i id='7t9GD'><tr id='7t9GD'><dt id='7t9GD'><q id='7t9GD'><span id='7t9GD'><b id='7t9GD'><form id='7t9GD'><ins id='7t9GD'></ins><ul id='7t9GD'></ul><sub id='7t9GD'></sub></form><legend id='7t9GD'></legend><bdo id='7t9GD'><pre id='7t9GD'><center id='7t9GD'></center></pre></bdo></b><th id='7t9GD'></th></span></q></dt></tr></i><div id='7t9GD'><tfoot id='7t9GD'></tfoot><dl id='7t9GD'><fieldset id='7t9GD'></fieldset></dl></div>

  • <small id='7t9GD'></small><noframes id='7t9GD'>

    • <bdo id='7t9GD'></bdo><ul id='7t9GD'></ul>

      <legend id='7t9GD'><style id='7t9GD'><dir id='7t9GD'><q id='7t9GD'></q></dir></style></legend>

        如何在不依赖数据库的情况下启动 spring-boot 应用程序?

        时间:2023-06-02

            <tbody id='oGpwv'></tbody>

          <small id='oGpwv'></small><noframes id='oGpwv'>

            <bdo id='oGpwv'></bdo><ul id='oGpwv'></ul>

            <i id='oGpwv'><tr id='oGpwv'><dt id='oGpwv'><q id='oGpwv'><span id='oGpwv'><b id='oGpwv'><form id='oGpwv'><ins id='oGpwv'></ins><ul id='oGpwv'></ul><sub id='oGpwv'></sub></form><legend id='oGpwv'></legend><bdo id='oGpwv'><pre id='oGpwv'><center id='oGpwv'></center></pre></bdo></b><th id='oGpwv'></th></span></q></dt></tr></i><div id='oGpwv'><tfoot id='oGpwv'></tfoot><dl id='oGpwv'><fieldset id='oGpwv'></fieldset></dl></div>
              1. <legend id='oGpwv'><style id='oGpwv'><dir id='oGpwv'><q id='oGpwv'></q></dir></style></legend>

                  <tfoot id='oGpwv'></tfoot>
                  本文介绍了如何在不依赖数据库的情况下启动 spring-boot 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的应用程序使用Spring-boot + Hibernate4 + mysql".作为其中的一部分,我有一个要求,即使数据库关闭,我的 sprint-boot 应用程序也应该能够启动.目前,当我尝试在没有数据库启动的情况下启动我的 Spring Boot 应用程序时,它会给出以下异常.

                  I am using "Spring-boot + Hibernate4 + mysql" for my application. As part of which I have a requirement where my sprint-boot app should be able to start even when database is down. Currently it gives the below exception when I try to start my spring boot app without DB being up.

                  我研究了很多,发现这个异常与 hibernate.temp.use_jdbc_metadata_defaults 属性有关.

                  I researched a lot and found out that this exception has to do with hibernate.temp.use_jdbc_metadata_defaults property.

                  我尝试在 spring boot 的application.yml"中设置它,但该属性的值在运行时没有反映.

                  I tried setting this in "application.yml" of spring boot but this property's value is not being reflected at runtime.

                  异常堆栈跟踪:

                  2014-05-25 04:09:43.193  INFO 59755 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
                  2014-05-25 04:09:43.250  WARN 59755 --- [           main] o.h.e.jdbc.internal.JdbcServicesImpl     : HHH000342: Could not obtain connection to query metadata : Communications link failure
                  
                  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
                  2014-05-25 04:09:43.263  INFO 59755 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
                  
                  Error starting ApplicationContext. To display the auto-configuration report enabled debug logging (start with --debug)
                  
                  
                  Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
                      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
                      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
                      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
                      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
                      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
                      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
                      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
                      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
                      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
                      at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
                      at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
                      at org.springframework.boot.SpringApplication.run(SpringApplication.java:898)
                      at admin.Application.main(Application.java:36)
                  Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
                      at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
                      at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
                      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:205)
                      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
                      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
                      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
                      at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
                      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
                      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
                      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
                      at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)
                      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
                      at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150)
                      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
                      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
                      ... 15 more
                  

                  application.yml:

                  spring:   
                    jpa:
                  show-sql: true
                  hibernate:
                    ddl-auto: none
                    naming_strategy: org.hibernate.cfg.DefaultNamingStrategy
                    temp:
                      use_jdbc_metadata_defaults: false
                  

                  推荐答案

                  这确实是一个难以破解的难题.

                  It was indeed a tough nut to crack.

                  经过大量研究并实际调试 spring-boot、spring、hibernate、tomcat 池等以完成它.

                  After lot and lot of research and actually debugging the spring-boot, spring, hibernate, tomcat pool, etc to get it done.

                  我确实认为这会为尝试实现此类要求的人节省大量时间.

                  I do think that it will save lot of time for people trying to achieve this type of requirement.

                  以下是实现以下要求所需的设置

                  Below are the settings required to achieve the following requirement

                  1. 即使数据库关闭或没有数据库,Spring 启动应用程序也能正常启动.
                  2. 应用程序将在数据库启动时即时获取连接,这意味着无需重新启动网络服务器或重新部署应用程序.
                  3. 如果数据库从运行状态关闭并再次启动,则无需启动 tomcat 或重新部署应用程序.

                  application.yml :

                  application.yml :

                  spring:
                    datasource:
                      driverClassName: com.mysql.jdbc.Driver
                      url: jdbc:mysql://localhost:3306/schema
                      username: root
                      password: root
                      continueOnError: true
                      initialize: false
                      initialSize: 0
                      timeBetweenEvictionRunsMillis: 5000
                      minEvictableIdleTimeMillis: 5000
                      minIdle: 0
                  
                    jpa:
                      show-sql: true
                      hibernate:
                        ddl-auto: none
                        naming_strategy: org.hibernate.cfg.DefaultNamingStrategy
                      properties:
                        hibernate:   
                          dialect: org.hibernate.dialect.MySQL5Dialect
                          hbm2ddl:
                            auto: none
                          temp:
                            use_jdbc_metadata_defaults: false
                  

                  这篇关于如何在不依赖数据库的情况下启动 spring-boot 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:LEFT JOIN 仅第一行 下一篇:如果表中的一行不存在,我如何更新或插入它?

                  相关文章

                  1. <i id='qVuJP'><tr id='qVuJP'><dt id='qVuJP'><q id='qVuJP'><span id='qVuJP'><b id='qVuJP'><form id='qVuJP'><ins id='qVuJP'></ins><ul id='qVuJP'></ul><sub id='qVuJP'></sub></form><legend id='qVuJP'></legend><bdo id='qVuJP'><pre id='qVuJP'><center id='qVuJP'></center></pre></bdo></b><th id='qVuJP'></th></span></q></dt></tr></i><div id='qVuJP'><tfoot id='qVuJP'></tfoot><dl id='qVuJP'><fieldset id='qVuJP'></fieldset></dl></div>
                      <bdo id='qVuJP'></bdo><ul id='qVuJP'></ul>

                      <legend id='qVuJP'><style id='qVuJP'><dir id='qVuJP'><q id='qVuJP'></q></dir></style></legend>
                    1. <small id='qVuJP'></small><noframes id='qVuJP'>

                    2. <tfoot id='qVuJP'></tfoot>