Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot H2数据库的data.sql脚本在我的应用程序为SpringBoot运行后执行_Spring Boot_Jpa_H2_Sql Scripts - Fatal编程技术网

Spring boot H2数据库的data.sql脚本在我的应用程序为SpringBoot运行后执行

Spring boot H2数据库的data.sql脚本在我的应用程序为SpringBoot运行后执行,spring-boot,jpa,h2,sql-scripts,Spring Boot,Jpa,H2,Sql Scripts,我假设H2数据库的data.sql脚本是在应用程序运行后执行的,因此findById()(CRUD方法)不会获取任何数据(NULL)。我怎样才能解决这个问题 请查找我的日志详细信息: 2020-10-12 18:52:01.361 INFO 30872 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]

我假设H2数据库的data.sql脚本是在应用程序运行后执行的,因此findById()(CRUD方法)不会获取任何数据(NULL)。我怎样才能解决这个问题

请查找我的日志详细信息:

2020-10-12 18:52:01.361  INFO 30872 --- [         task-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-10-12 18:52:01.491  INFO 30872 --- [         task-1] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.21.Final
2020-10-12 18:52:01.735  INFO 30872 --- [         task-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-10-12 18:52:01.956  INFO 30872 --- [         task-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Hibernate: drop table if exists monitoring_app CASCADE 
Hibernate: create table monitoring_app (id integer generated by default as identity, grep_parameter varchar(255), service_name varchar(255), hostname varchar(255), log_file_name varchar(255), log_file_path varchar(255), max_failed_retries integer not null, restart_sleep_time_secs integer not null, service_failure char(255), primary key (id))
2020-10-12 18:52:02.982  INFO 30872 --- [         task-1] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-10-12 18:52:02.990  INFO 30872 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
Hibernate: select monitoring0_.id as id1_0_, monitoring0_.grep_parameter as grep_par2_0_, monitoring0_.service_name as service_3_0_, monitoring0_.hostname as hostname4_0_, monitoring0_.log_file_name as log_file5_0_, monitoring0_.log_file_path as log_file6_0_, monitoring0_.max_failed_retries as max_fail7_0_, monitoring0_.restart_sleep_time_secs as restart_8_0_, monitoring0_.service_failure as service_9_0_ from monitoring_app monitoring0_ where monitoring0_.hostname=?
list is[]
Hibernate: select monitoring0_.id as id1_0_0_, monitoring0_.grep_parameter as grep_par2_0_0_, monitoring0_.service_name as service_3_0_0_, monitoring0_.hostname as hostname4_0_0_, monitoring0_.log_file_name as log_file5_0_0_, monitoring0_.log_file_path as log_file6_0_0_, monitoring0_.max_failed_retries as max_fail7_0_0_, monitoring0_.restart_sleep_time_secs as restart_8_0_0_, monitoring0_.service_failure as service_9_0_0_ from monitoring_app monitoring0_ where monitoring0_.id=?
Hibernate: insert into monitoring_app (id, grep_parameter, service_name, hostname, log_file_name, log_file_path, max_failed_retries, restart_sleep_time_secs, service_failure) values (null, ?, ?, ?, ?, ?, ?, ?, ?)
2020-10-12 18:52:03.679  INFO 30872 --- [         task-2] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2020-10-12 18:52:03.762  WARN 30872 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : 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
2020-10-12 18:52:04.283  INFO 30872 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-10-12 18:52:04.286  INFO 30872 --- [  restartedMain] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-10-12 18:52:04.287  INFO 30872 --- [  restartedMain] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-10-12 18:52:04.298  INFO 30872 --- [  restartedMain] c.m.automation.AutomationApplication     : Started AutomationApplication in 7.785 seconds (JVM running for 8.729)
更新: 请找到我的data.sql

插入示例值(默认值为'a'、'b'、'c'、'd'、'e'、'f',1,2,'y'); 插入示例值(默认值为'g'、'h'、'i'、'j'、'k'、'l',2,3,'n'); 这是木刀班

@组成部分 公共类示例DAO{

@Autowired
ExampleRepository exampleRepository;

public ArrayList<Example> dbFetchDetails(String var)
{
    ArrayList<Example> exampleList = new ArrayList<>();
    exampleList= exampleRepository.findByVar(var);
   return exampleList;
    }} 
//添加了getters setters和constructor
}

您需要提供data.sql和有关如何调用findById()方法的代码。请在上面的帖子中查找更新,然后检查启动后数据是否已插入数据库?您可以使用h2-console进行检查。这就是问题所在,在程序执行之前没有插入data.sql。它只在程序执行后才执行。因此,我的h2数据库仍然是空的,并且我无法从数据库中获取任何内容,因为在对数据库进行findBy()调用时,它是空的。我在程序运行期间进行的任何save()调用都将被执行。意思是说它能够访问数据库。data.sql只有在程序运行后才会初始化。我还想知道为什么h2中的实体和java中的我的实体的参数顺序会发生变化,以及如何克服这个问题?我已经使用@PostConstruct调用了我的服务类方法。这就是问题所在吗?如果是这样的话,那么在应用程序启动时,在没有控制器的情况下,什么样的替换注释可以开始触发我的服务层中的方法呢?
ArrayList<Example> findByVar(String Var);
@Id @GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String a;
private String b;
private String c;
private String d;
private int e;
private int f;
private String g;
private String h;
private Character i;