当前位置: 首页 > 知识库问答 >
问题:

Spring Boot 2.0.0.release-不运行h2data.sql

颛孙成益
2023-03-14

使用h2的简单Spring Boot应用程序,它有一个通过data.sql填充的DB表。与spring-boot-starter-parent 1.5.9的工作效率为100%。如果我切换到2.0.0,则释放。启动时不再运行data.sql。

在我的pom.xml中

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

......

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
     <!-- <version>2.0.0.RELEASE</version> -->  
    <version>1.5.9.RELEASE</version>

    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
     <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>     
        <scope>runtime</scope>       
    </dependency>


</dependencies>

......

和一个插入到src/main/resources/data.SQL下的数据库表中的SQL文件

spring.datasource.url=jdbc:h2:file:~/greeter;AUTO_SERVER=TRUE
spring.datasource.initialization-mode=always

spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop

使用1.5.9.在启动时释放在日志中,您可以看到:

2018-07-23 17:53:41.219  INFO 11404 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
Hibernate: drop table greeting if exists
Hibernate: create table greeting (id bigint not null, action varchar(255), say varchar(255), primary key (id))
2018-07-23 17:53:41.238  INFO 11404 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2018-07-23 17:53:41.341  INFO 11404 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-07-23 17:53:41.590  INFO 11404 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executing SQL script from URL [file:/..../classes/data.sql]

使用2.0.0.Release

似乎没有从我的application.properties文件中提取任何内容。数据库没有被删除/重新创建,也没有将Data.sql导入到数据库中。和日志如下;不知何故,它似乎与Maven有关。出现问题的启动日志

2018-07-23 21:16:39.532  INFO 3600 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2018-07-23 21:16:39.741  INFO 3600 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2018-07-23 21:16:39.880  INFO 3600 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-07-23 21:16:39.911  INFO 3600 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-07-23 21:16:40.114  INFO 3600 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.14.Final}
2018-07-23 21:16:40.119  INFO 3600 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-07-23 21:16:40.382  INFO 3600 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-07-23 21:16:40.685  INFO 3600 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2018-07-23 21:16:41.840  INFO 3600 --- [  restartedMain] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@542d091e'
2018-07-23 21:16:41.850  INFO 3600 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-07-23 21:16:43.574  INFO 3600 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@29bb347c: startup date [Mon Jul 23 21:16:33 CAT 2018]; root of context hierarchy
2018-07-23 21:16:43.710  WARN 3600 --- [  restartedMain] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning

除了pom.xml中的版本改变之外,没有别的东西...

在Spring2.0.0.Release中需要什么来运行它?

EDIT 1 EDIT 1 EDIT 1 EDIT 1似乎与Maven依赖关系有关???????如果我在pom.xml中包含如下所示的存储库,就可以了...删除它们我有上面提到的问题

<repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>  

共有1个答案

仲君昊
2023-03-14

确保在从H2-Console连接时使用JDBC:h2:mem:testdb作为JDBC URL。当我们有h2(jdbc:h2:~/test)提供的默认url时,您将看不到数据库中的脚本结果。

另外,要在控制台上查看调试,只需将debug=true放入application.properties文件中。

内存中

 类似资料:
  • [信息][错误]无法执行目标org.apache.maven.plugins:maven-deploy-plugin:2.7:在项目模型上部署(default-deploy):无法部署项目:无法将项目COM传输。test:model:jar:0.1.0从/到central(http://localhost:8081/artifactory/libs-release/com/srcrea/model

  • When run, this command line interface automatically generates a new GitHub Release and populates it with the changes (commits) made since the last release. Usage Firstly, install the package from npm

  • 8.0.0 Released on 5th of August, 2020Major changes This version introduces a completely new architecture for row and column management - index mapper, which is responsible for the storage and manageme

  • 0.24.4 (2014-08-09) pem file is used by mockserver and required by scrapy bench (commit 5eddc68) scrapy bench needs scrapy.tests* (commit d6cb999) 0.24.3 (2014-08-09) no need to waste travis-ci time o

  • v10.0.0 This is the first development release for the Jewel cycle. Notable Changes build: cmake tweaks (pr#6254, John Spray) build: more CMake package check fixes (pr#6108, Daniel Gryniewicz) ceph-dis

  • Release It! �� �� Generic CLI tool to automate versioning and package publishing related tasks: Bump version (in e.g. package.json) Git commit, tag, push Execute any (test or build) commands using hoo