当我在存储库中编写一些JPA查询时,Spring引导停止

时间:2016-08-01 05:39:53

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

我在H2数据库中使用spring boot。我的应用程序在控制台上以下面的文本停止。

2016-08-01 10:36:08.610  INFO 3920 --- [ost-startStop-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2016-08-01 10:36:08.651  INFO 3920 --- [ost-startStop-1] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.11.Final}
2016-08-01 10:36:08.651  INFO 3920 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2016-08-01 10:36:08.651  INFO 3920 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2016-08-01 10:36:08.801  INFO 3920 --- [ost-startStop-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-08-01 10:36:09.031  INFO 3920 --- [ost-startStop-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2016-08-01 10:36:09.131  INFO 3920 --- [ost-startStop-1] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2016-08-01 10:36:09.291  INFO 3920 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2016-08-01 10:36:09.291  INFO 3920 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000102: Fetching database metadata
2016-08-01 10:36:09.301  INFO 3920 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000396: Updating schema
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000261: Table found: TEST.PUBLIC.EMAILDATA
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000037: Columns: [quantity, emailto, id, autostart, emailfrom]
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000108: Foreign keys: []
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000126: Indexes: [primary_key_2]
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000261: Table found: TEST.PUBLIC.STATUS
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000037: Columns: [exchangefile, consolidate, processdate, aggregateall, scriptmaster, sendmail, id, insiderstrade]
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000108: Foreign keys: []
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000126: Indexes: [primary_key_9]
2016-08-01 10:36:09.311  INFO 3920 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000232: Schema update complete

我的存储库是:

@Transactional
public interface EmailDataRepository extends JpaRepository<EmailData,Long>{
      @Query("SELECT p FROM EmailData P")
      public EmailData findLastRow();
}

DBConfig是:

@Configuration
@EnableTransactionManagement
@ComponentScan("com.demo.*")
@PropertySource("classpath:application.properties")
@EntityScan(basePackages = {"com.demo.model"})
@EnableJpaRepositories("com.demo.repository.main")
public class DBConfig {....}

型号:

@Entity
@Table(name="EmailData")
public class EmailData {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;
    private String emailTo;
    private String emailFrom;   
    private String quantity;
    private Boolean autoStart;
...}

1 个答案:

答案 0 :(得分:0)

您的H2数据库网址应具有以下配置

DB_CLOSE_ON_EXIT=FALSE

Spring Boot文档有一个引用:

  

如果由于某种原因,您确实为嵌入式数据库配置了连接URL,则应注意确保禁用数据库的自动关闭。如果您正在使用H2,则应使用DB_CLOSE_ON_EXIT = FALSE来执行此操作。如果您正在使用HSQLDB,则应确保不使用shutdown = true。禁用数据库的自动关闭允许Spring Boot控制数据库何时关闭,从而确保一旦不再需要访问数据库就会发生这种情况。