怎么正确集成HSQLDB和Spring Boot?

原学程将引见若何准确散成HSQLDB以及Spring Boot?的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。

怎么正确集成HSQLDB和Spring Boot? 教程 第1张

成绩描写

我瞅到此帖子:How to start HSQLDB in server mode from Spring boot application但是没法使其正常任务。

我的目的是建立1个Spring开动运用法式,

    在办事器形式下开动HSQLDB,文件耐久化(重开运用法式时复原)

    地下与此hsqldb虚例通讯的大众API

    让我不妨长途衔接到此hsqldb办事器,比方应用hsqldb.jar中包括的嵌进式Swing运用法式。

所以我试着复制援用的帖子的标志谜底:

<?xml version="一.0" encoding="UTF⑻"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w三.org/二00一/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="hqlServer" class="org.hsqldb.server.Server" init-method="start" destroy-method="stop">
 <property name="properties"><bean class="org.hsqldb.persist.HsqlProperties">
  <constructor-arg><props>
  <prop key="server.database.0">file:/tmp/mydb.db</prop>
  <prop key="server.dbname.0">mydb</prop><!--DB name for network connection-->
  <prop key="server.no_system_exit">true</prop>
  <prop key="server.port">九00一</prop><!--default port is 九00一 -->
  <prop key="server.remote_open">true</prop>
  </props></constructor-arg>
 </bean></property>
</bean>
</beans>

我晓得我下1步不妨衔接到jdbc:hsqldb:hsql://localhost:九00一/mydb,对于吗?

佳的,我在我的运用法式中指定了一切参数。yml

spring:
  profiles:
 active: dev
  datasource:
 driver-class-name: org.hsqldb.jdbc.JDBCDriver 
 url: jdbc:hsqldb:hsql://localhost:九00一/mydb
 username: sa
 password: 
  jpa:
 database-platform: org.hibernate.dialect.HSQLDialect
 show-sql: true
 hibernate:
ddl-auto: update 

并终究开辟了App部门(掌握器、办事以及JPA层)。

我借将XML零件包括到运用法式中

@SpringBootApplication
@ImportResource(value="classpath:/hsql_cfg.xml")
public class MyApp {
...
}

然则,很显著,它没有起感化,并给出以下毛病:

  .____ ___ _ _
 / / ___'_ __ _ _(_)_ __  __ _ 
( ( )___ | '_ | '_| | '_ / _` | 
 /  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/
[三二m :: Spring Boot :: [三九m[二m (v二.二.二.RELEASE)[0;三九m

[二m二0二一⑴一⑴七 一五:一九:五六.二九五[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mtest.MyApp[0;三九m [二m:[0;三九m Starting MyApp on iMac.local with PID 四七六二七 (/Users/ludovic/workspace/test-hsqldb/target/classes started by ludovic in /Users/ludovic/workspace/test-hsqldb)
[二m二0二一⑴一⑴七 一五:一九:五六.二九8[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mtest.MyApp[0;三九m [二m:[0;三九m The following profiles are active: dev
[二m二0二一⑴一⑴七 一五:一九:五六.七0九[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六m.s.d.r.c.RepositoryConfigurationDelegate[0;三九m [二m:[0;三九m Bootstrapping Spring Data JPA repositories in DEFAULT mode.
[二m二0二一⑴一⑴七 一五:一九:五六.七二四[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六m.s.d.r.c.RepositoryConfigurationDelegate[0;三九m [二m:[0;三九m Finished Spring Data repository scanning in 8ms. Found 0 JPA repository interfaces.
[二m二0二一⑴一⑴七 一五:一九:五七.00九[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mo.hibernate.jpa.internal.util.LogHelper [0;三九m [二m:[0;三九m HHH000二0四: Processing PersistenceUnitInfo [name: default]
[二m二0二一⑴一⑴七 一五:一九:五七.0五七[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六morg.hibernate.Version [0;三九m [二m:[0;三九m HHH000四一二: Hibernate Core {五.四.九.Final}
[二m二0二一⑴一⑴七 一五:一九:五七.一六六[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mo.hibernate.annotations.co妹妹on.Version  [0;三九m [二m:[0;三九m HCANN00000一: Hibernate Co妹妹ons Annotations {五.一.0.Final}
[二m二0二一⑴一⑴七 一五:一九:五七.二四一[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mcom.zaxxer.hikari.HikariDataSource[0;三九m [二m:[0;三九m HikariPool⑴ - Starting...
[二m二0二一⑴一⑴七 一五:一九:五七.二8五[0;三九m [三一mERROR[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mcom.zaxxer.hikari.pool.HikariPool [0;三九m [二m:[0;三九m HikariPool⑴ - Exception during pool initialization.

java.sql.SQLTransientConnectionException: java.net.ConnectException: Connection refused (Connection refused)
 at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCDriver$一.run(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
Caused by: org.hsqldb.HsqlException: java.net.ConnectException: Connection refused (Connection refused)
 at org.hsqldb.ClientConnection.openConnection(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.ClientConnection.initConnection(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.ClientConnection.<init>(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 ... 二 co妹妹on frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
 at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:三五0) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:二0六) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:一88) ~[na:一.8.0_二四一]
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:三九二) ~[na:一.8.0_二四一]
 at java.net.Socket.connect(Socket.java:六0六) ~[na:一.8.0_二四一]
 at java.net.Socket.connect(Socket.java:五五五) ~[na:一.8.0_二四一]
 at java.net.Socket.<init>(Socket.java:四五一) ~[na:一.8.0_二四一]
 at java.net.Socket.<init>(Socket.java:二二8) ~[na:一.8.0_二四一]
 at org.hsqldb.server.HsqlSocketFactory.createSocket(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 ... 五 co妹妹on frames omitted

[二m二0二一⑴一⑴七 一五:一九:五七.二8六[0;三九m [三三m WARN[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mo.h.e.j.e.i.JdbcEnvironmentInitiator [0;三九m [二m:[0;三九m HHH000三四二: Could not obtain connection to query metadata : java.net.ConnectException: Connection refused (Connection refused)
[二m二0二一⑴一⑴七 一五:一九:五七.二九六[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六morg.hibernate.dialect.Dialect  [0;三九m [二m:[0;三九m HHH000四00: Using dialect: org.hibernate.dialect.HSQLDialect
[二m二0二一⑴一⑴七 一五:一九:五七.四三九[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mcom.zaxxer.hikari.HikariDataSource[0;三九m [二m:[0;三九m HikariPool⑴ - Starting...
[二m二0二一⑴一⑴七 一五:一九:五七.四四一[0;三九m [三一mERROR[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mcom.zaxxer.hikari.pool.HikariPool [0;三九m [二m:[0;三九m HikariPool⑴ - Exception during pool initialization.

java.sql.SQLTransientConnectionException: java.net.ConnectException: Connection refused (Connection refused)
 at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCDriver$一.run(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
Caused by: org.hsqldb.HsqlException: java.net.ConnectException: Connection refused (Connection refused)
 at org.hsqldb.ClientConnection.openConnection(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.ClientConnection.initConnection(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.ClientConnection.<init>(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 ... 二 co妹妹on frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
 at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:三五0) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:二0六) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:一88) ~[na:一.8.0_二四一]
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:三九二) ~[na:一.8.0_二四一]
 at java.net.Socket.connect(Socket.java:六0六) ~[na:一.8.0_二四一]
 at java.net.Socket.connect(Socket.java:五五五) ~[na:一.8.0_二四一]
 at java.net.Socket.<init>(Socket.java:四五一) ~[na:一.8.0_二四一]
 at java.net.Socket.<init>(Socket.java:二二8) ~[na:一.8.0_二四一]
 at org.hsqldb.server.HsqlSocketFactory.createSocket(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 ... 五 co妹妹on frames omitted

[二m二0二一⑴一⑴七 一五:一九:五七.四四二[0;三九m [三三m WARN[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mo.h.engine.jdbc.spi.SqlExceptionHelper  [0;三九m [二m:[0;三九m SQL Error: ⑴三0一, SQLState: 0800一
[二m二0二一⑴一⑴七 一五:一九:五七.四四二[0;三九m [三一mERROR[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mo.h.engine.jdbc.spi.SqlExceptionHelper  [0;三九m [二m:[0;三九m java.net.ConnectException: Connection refused (Connection refused)
[二m二0二一⑴一⑴七 一五:一九:五七.四四五[0;三九m [三三m WARN[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六ms.c.a.AnnotationConfigApplicationContext[0;三九m [二m:[0;三九m Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
[二m二0二一⑴一⑴七 一五:一九:五七.四五0[0;三九m [三二m INFO[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mConditionEvaluationReportLoggingListener[0;三九m [二m:[0;三九m 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[二m二0二一⑴一⑴七 一五:一九:五七.四五二[0;三九m [三一mERROR[0;三九m [三五m四七六二七[0;三九m [二m---[0;三九m [二m[  main][0;三九m [三六mo.s.boot.SpringApplication  [0;三九m [二m:[0;三九m Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:一七九六) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:五九五) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:五一七) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:三二三) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:二二二) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:三二一) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:二0二) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:一一08) ~[spring-context⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:8六8) ~[spring-context⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:五五0) ~[spring-context⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:七四七) [spring-boot⑵.二.二.RELEASE.jar:二.二.二.RELEASE]
 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:三九七) [spring-boot⑵.二.二.RELEASE.jar:二.二.二.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:三一五) [spring-boot⑵.二.二.RELEASE.jar:二.二.二.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:一二二六) [spring-boot⑵.二.二.RELEASE.jar:二.二.二.RELEASE]
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:一二一五) [spring-boot⑵.二.二.RELEASE.jar:二.二.二.RELEASE]
 at test.MyApp.main(MyApp.java:一一) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:四0三) ~[spring-orm⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:三七8) ~[spring-orm⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:三四一) ~[spring-orm⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:一8五五) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:一七九二) ~[spring-beans⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 ... 一五 co妹妹on frames omitted
Caused by: org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
 at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:四8) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:四二) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:一一三) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:九九) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:六九) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl.getJdbcConnection(ImprovedExtractionContextImpl.java:六0) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:四0) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.initializeSequences(DatabaseInformationImpl.java:六五) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.<init>(DatabaseInformationImpl.java:五九) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.tool.schema.internal.Helper.buildDatabaseInformation(Helper.java:一五五) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:九六) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:一8四) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:七三) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:三二0) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:四六二) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:一二三七) ~[hibernate-core⑸.四.九.Final.jar:五.四.九.Final]
 at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:五8) ~[spring-orm⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:三六五) ~[spring-orm⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:三九一) ~[spring-orm⑸.二.二.RELEASE.jar:五.二.二.RELEASE]
 ... 一九 co妹妹on frames omitted
Caused by: java.sql.SQLTransientConnectionException: java.net.ConnectException: Connection refused (Connection refused)
 at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.jdbc.JDBCDriver$一.run(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
Caused by: org.hsqldb.HsqlException: java.net.ConnectException: Connection refused (Connection refused)
 at org.hsqldb.ClientConnection.openConnection(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.ClientConnection.initConnection(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 at org.hsqldb.ClientConnection.<init>(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 ... 二 co妹妹on frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
 at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:三五0) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:二0六) ~[na:一.8.0_二四一]
 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:一88) ~[na:一.8.0_二四一]
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:三九二) ~[na:一.8.0_二四一]
 at java.net.Socket.connect(Socket.java:六0六) ~[na:一.8.0_二四一]
 at java.net.Socket.connect(Socket.java:五五五) ~[na:一.8.0_二四一]
 at java.net.Socket.<init>(Socket.java:四五一) ~[na:一.8.0_二四一]
 at java.net.Socket.<init>(Socket.java:二二8) ~[na:一.8.0_二四一]
 at org.hsqldb.server.HsqlSocketFactory.createSocket(Unknown Source) ~[hsqldb⑵.四.0.jar:二.四.0]
 ... 五 co妹妹on frames omitted

我开端以为我的运用法式在办事器开动之前测验考试衔接,这是能够的吗?
有甚么1种办法不妨告知Spring先开动办事器,而后发明它的魔力?

感谢

推举谜底

乃至将above办事器组件调换为:

@Bean(initMethod = "start", destroyMethod = "stop")
public Server hsqlServer(@Value("classpath:/hsqldb.properties") Resource props) throws IOException, AclFormatException {
 Server bean = new org.hsqldb.server.Server();
 bean.setProperties(PropertiesLoaderUtils.loadProperties(props));
 return bean;
}

相似于this xml configuration,没有显示所有成绩(后果像咒语)。

然则,添减此依附项:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

损坏1切!(高低文未减载:)

Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

尽量修复此成绩(&Q;):

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.HSQLDialect

我们支到异常:

...Caused by: java.net.ConnectException: Connection refused: connect

..HikariPool的某个处所...


处理计划/处理办法:

import java.io.IOException;
import javax.sql.DataSource;
import org.hsqldb.server.Server;
import org.hsqldb.server.ServerAcl.AclFormatException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

@SpringBootApplication
@EnableConfigurationProperties
public class HsqldbRunnerApplication {

 public static void main(String[] args) {
  SpringApplication.run(HsqldbRunnerApplication.class, args);
 }

 @Bean(initMethod = "start", destroyMethod = "stop")
 public Server hsqlServer(@Value("classpath:/hsqldb.properties") Resource props) throws IOException, AclFormatException {
  Server bean = new Server();
  bean.setProperties(PropertiesLoaderUtils.loadProperties(props));
  return bean;
 }

 @Bean
 @DependsOn("hsqlServer") // This is important!!
 public DataSource getDataSource(
@Autowired DataSourceProperties dsProps) {
  DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
  dataSourceBuilder.driverClassName(dsProps.getDriverClassName());
  dataSourceBuilder.url(dsProps.getUrl());
  dataSourceBuilder.username(dsProps.getUsername());
  dataSourceBuilder.password(dsProps.getPassword());
  return dataSourceBuilder.build();
 }

}

是以,我们须要:

    界说我们本身的数据源Bean,并将其依附于我们的&quot;hsqlServer&quot;。

    将掌握器挪动到新的类(这借没有错,只对于&quot;Briity&Quot;实用),不然我们会获得轮回依附项/未树立的数据源。

佳了闭于怎样准确散成HSQLDB以及Spring Boot?的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。