【问题标题】:Spring Data JPA - Error creating bean with name 'entityManagerFactory'Spring Data JPA - 创建名为“entityManagerFactory”的bean时出错
【发布时间】:2020-06-20 19:19:12
【问题描述】:

我正在试用 Spring Data。我有一个非常基本的应用程序。 部分 : 1.主要应用类

@SpringBootApplication
public class CurrencyExchangeServiceApplication {

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

}
  1. 然后我有我的 POM.XML

    https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.13.发布 com.italktocomputer.spring-boot-microservices 货币兑换服务 0.0.1-快照 货币兑换服务 Spring Boot 演示项目

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR5</spring-cloud.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    

应用程序运行良好,但是当我添加 data.sql 文件时:

insert into exchange_value (id,currencyFrom, currencyTo, exchangeRate) values (10000,'USD','CAD',1);

我收到以下错误:

2020-03-08 15:42:39.836  INFO 7053 --- [  restartedMain] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-03-08 15:42:39.869  INFO 7053 --- [  restartedMain] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=currency-exchange-service, profiles=[default], label=null, version=eaf703d5fc6fba5debfc8a23c08c6ec936082d16, state=null
2020-03-08 15:42:39.869  INFO 7053 --- [  restartedMain] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}]
2020-03-08 15:42:39.870  INFO 7053 --- [  restartedMain] i.s.c.CurrencyExchangeServiceApplication : No active profile set, falling back to default profiles: default
2020-03-08 15:42:40.089  INFO 7053 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-08 15:42:40.091  INFO 7053 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1ms. Found 0 JPA repository interfaces.
2020-03-08 15:42:40.118  INFO 7053 --- [  restartedMain] o.s.cloud.context.scope.GenericScope     : BeanFactory id=3ba16513-849a-3407-8710-797184dfd4c9
2020-03-08 15:42:40.191  INFO 7053 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8000 (http)
2020-03-08 15:42:40.192  INFO 7053 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-03-08 15:42:40.192  INFO 7053 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-08 15:42:40.198  INFO 7053 --- [  restartedMain] o.a.c.c.C.[Tomcat-22].[localhost].[/]    : Initializing Spring embedded WebApplicationContext
2020-03-08 15:42:40.198  INFO 7053 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 327 ms
2020-03-08 15:42:40.349  INFO 7053 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-34 - Starting...
2020-03-08 15:42:40.350  INFO 7053 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-34 - Start completed.
2020-03-08 15:42:40.355  INFO 7053 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2020-03-08 15:42:40.359  INFO 7053 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Hibernate: drop table exchange_curreny if exists
Hibernate: create table exchange_curreny (id integer not null, currency_from varchar(255), currency_to varchar(255), exchange_rate decimal(19,2), primary key (id))
2020-03-08 15:42:40.746  INFO 7053 --- [  restartedMain] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@65386fb9'
2020-03-08 15:42:40.746  INFO 7053 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-03-08 15:42:40.753  WARN 7053 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : Unable to start LiveReload server
2020-03-08 15:42:40.755  WARN 7053 --- [  restartedMain] ConfigServletWebServerApplicationContext : 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]: Initialization of bean failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/Users/nikku/Downloads/currency-exchange-service/target/classes/data.sql]: insert into exchange_value (id,currencyFrom, currencyTo, exchangeRate) values (10000,'USD','CAD',1); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "EXCHANGE_VALUE" not found; SQL statement:
insert into exchange_value (id,currencyFrom, currencyTo, exchangeRate) values (10000,'USD','CAD',1) [42102-200]
2020-03-08 15:42:40.959  WARN 7053 --- [  restartedMain] o.s.b.f.support.DisposableBeanAdapter    : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-200]
2020-03-08 15:42:40.959  INFO 7053 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-34 - Shutdown initiated...
2020-03-08 15:42:40.963  INFO 7053 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-34 - Shutdown completed.
2020-03-08 15:42:40.963  INFO 7053 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-03-08 15:42:40.970  INFO 7053 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-08 15:42:40.971 ERROR 7053 --- [  restartedMain] o.s.boot.SpringApplication               : 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]: Initialization of bean failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/Users/nikku/Downloads/currency-exchange-service/target/classes/data.sql]: insert into exchange_value (id,currencyFrom, currencyTo, exchangeRate) values (10000,'USD','CAD',1); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "EXCHANGE_VALUE" not found; SQL statement:
insert into exchange_value (id,currencyFrom, currencyTo, exchangeRate) values (10000,'USD','CAD',1) [42102-200]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at com.italktocomputer.springbootmicroservices.currencyexchangeservice.CurrencyExchangeServiceApplication.main(CurrencyExchangeServiceApplication.java:10) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_222]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_222]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_222]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_222]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.13.RELEASE.jar:2.1.13.RELEASE]
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/Users/nikku/Downloads/currency-exchange-service/target/classes/data.sql]: insert into exchange_value (id,currencyFrom, currencyTo, exchangeRate) values (10000,'USD','CAD',1); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "EXCHANGE_VALUE" not found; SQL statement:
insert into exchange_value (id,currencyFrom, currencyTo, exchangeRate) values (10000,'USD','CAD',1) [42102-200]
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:509) ~[spring-jdbc-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:239) ~[spring-jdbc-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:49) ~[spring-jdbc-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.runScripts(DataSourceInitializer.java:202) ~[spring-boot-autoconfigure-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.initSchema(DataSourceInitializer.java:119) ~[spring-boot-autoconfigure-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.onApplicationEvent(DataSourceInitializerInvoker.java:89) ~[spring-boot-autoconfigure-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.onApplicationEvent(DataSourceInitializerInvoker.java:37) ~[spring-boot-autoconfigure-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.publishEventIfRequired(DataSourceInitializedPublisher.java:99) ~[spring-boot-autoconfigure-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.postProcessAfterInitialization(DataSourceInitializedPublisher.java:90) ~[spring-boot-autoconfigure-2.1.13.RELEASE.jar:2.1.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:429) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1775) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    ... 20 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "EXCHANGE_VALUE" not found; SQL statement:
insert into exchange_value (id,currencyFrom, currencyTo, exchangeRate) values (10000,'USD','CAD',1) [42102-200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:453) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:205) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:181) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.readTableOrView(Parser.java:7628) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.readTableOrView(Parser.java:7599) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parseInsert(Parser.java:1747) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parsePrepared(Parser.java:954) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parse(Parser.java:843) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parse(Parser.java:815) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.prepareCommand(Parser.java:738) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.engine.Session.prepareLocal(Session.java:657) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.engine.Session.prepareCommand(Session.java:595) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:212) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201) ~[h2-1.4.200.jar:1.4.200]
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.2.0.jar:na]
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:488) ~[spring-jdbc-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    ... 36 common frames omitted

Application.Properties

spring.application.name = currency-exchange-service
server.port = 8000

spring.jpa.show-sql = true
spring.h2.console.enabled = true

实体类:

@Entity
public class ExchangeCurreny {

    ExchangeCurreny() {

    }

    public ExchangeCurreny(int id, String currencyFrom, String currencyTo, BigDecimal exchangeRate) {
        super();
        this.id = id;
        this.currencyFrom = currencyFrom;
        this.currencyTo = currencyTo;
        this.exchangeRate = exchangeRate;
    }
    @Id
    private int id;
    private String currencyFrom, currencyTo;
    private BigDecimal exchangeRate;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getCurrencyFrom() {
        return currencyFrom;
    }
    public void setCurrencyFrom(String currencyFrom) {
        this.currencyFrom = currencyFrom;
    }
    public String getCurrencyTo() {
        return currencyTo;
    }
    public void setCurrencyTo(String currencyTo) {
        this.currencyTo = currencyTo;
    }
    public BigDecimal getExchangeRate() {
        return exchangeRate;
    }
    public void setExchangeRate(BigDecimal exchangeRate) {
        this.exchangeRate = exchangeRate;
    }
}

我不知道发生了什么。感谢您的指导。

谢谢!

【问题讨论】:

  • 共享 application.properties 和 exchange_value 表实体
  • 查看错误信息:Table "EXCHANGE_VALUE" not found。您正在插入一个不存在的表
  • 我已经对我的 application.properties 进行了着色。我读了几个答案。他们说,当您的连接已经关闭时,您会收到该错误消息。
  • @dassum 共享实体类。
  • 只需在运行插入脚本或活动ddl-auto之前确保您的表存在,或在脚本中包含创建语句。

标签: spring spring-boot spring-data-jpa spring-data h2


【解决方案1】:

看看嵌套异常:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "EXCHANGE_VALUE" not found; SQL statement:

这意味着要么表不存在,要么至少找不到。 我假设 EXCHANGE_VALUE 实际上是数据库中表的名称(仔细检查拼写错误)。

您还可以检查您如何在 Java 中命名实体并尝试使用注释 @Table 显式声明表名。

@Table(name = "exchange_value")
public class ExchangeValue {}

【讨论】:

    【解决方案2】:

    我遇到了同样的错误,但我的错误是将实体放入与 @SpringBootApplication 类不同的包中。

    我的主类在“com.example.test”中,我的实体在包“com.example.test2.domain”中。

    当我将我的实体放入“com.example.test.domain”时,一切都恢复正常了。

    【讨论】:

      【解决方案3】:

      我已关注https://www.baeldung.com/spring-boot-data-sql-and-schema-sql

      1. 使用 Schema.sql 和 data.sql 创建和插入数据
      2. 这里是语法
      3. create table exchange_value (id bigint not null, fromvalue varchar(255), multiplication_factor double not null, to varchar(255), primary key (id)); -> Schema.sql
      4. insert into exchange_value (id,fromvalue,multiplication_factor,to) values (1,'USD',889,'INR'); --> data.sql
      5. 在您的 application.config 中添加 spring.jpa.hibernate.ddl-auto=none
      6. 记住关闭自动架构创建以避免冲突也很重要:这是给我答案的那一行

      `

      【讨论】:

        【解决方案4】:

        我也面临同样的问题,通过使用 schema.sql 以及带有相应 sql 脚本的 data.sql 文件并进入 application.properties 文件,通过以下方式解决:

        application.properties

        # h2 database Configuration
        spring.datasource.url = jdbc:h2:mem:testdb
        spring.datasource.username = sa
        spring.datasource.password = 
        spring.datasource.driver-class-name = org.h2.Driver
        spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
        spring.jpa.hibernate.ddl-auto = update
        
        spring.h2.console.enabled=true
        spring.h2.console.path=/h2-console
        

        schema.sql

        DROP TABLE IF EXISTS EXCHANGE_VALUE;  
        CREATE TABLE EXCHANGE_VALUE (  
        id INT PRIMARY KEY,  
        currency_from VARCHAR(3) NOT NULL,  
        currency_to VARCHAR(3) NOT NULL,  
        conversion_multiple INT(8) NOT NULL,
        port INT(5)
        );  
        

        data.sql

        insert into exchange_value(id,currency_from,currency_to,conversion_multiple,port)
            values(1001,'USD','INR',75,0);
        insert into exchange_value(id,currency_from,currency_to,conversion_multiple,port)
            values(1002,'SAR','INR',20,0);
        insert into exchange_value(id,currency_from,currency_to,conversion_multiple,port)
            values(1003,'EUR','INR',87,0);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-01-09
          • 1970-01-01
          • 2018-01-13
          • 1970-01-01
          • 1970-01-01
          • 2013-06-15
          • 2020-07-12
          相关资源
          最近更新 更多