Quando tento rodar o projeto aparece o seguinte erro : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Ramos/Documents/Lucas/Estagio/workspace-eclipse/forum/target/classes/data.sql]: INSERT INTO USUARIO(nome,email,senha) VALUES ('ALuno','aluno@email.com','12345'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USUARIO" not found; SQL statement: INSERT INTO USUARIO(nome,email,senha) VALUES ('ALuno','aluno@email.com','12345') [42102-200]
Código do Usuario
package br.com.alura.forum.modelo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Usuario {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nome;
private String email;
private String senha;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Usuario other = (Usuario) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}
Código do application.properties
# datasource
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:alura-forum
spring.datasource.username=sa
spring.datasource.password=
# jpa
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
# Nova propriedade a partir da versao 2.5 do Spring Boot:
spring.jpa.defer-datasource-initialization=true
# h2
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
Código do data.sql
INSERT INTO USUARIO(nome,email,senha) VALUES ('ALuno','aluno@email.com','12345');
INSERT INTO CURSO(nome, categoria) VALUES ('Spring boot','Programação');
INSERT INTO CURSO(nome, categoria) VALUES ('HTML5','Front-end');
INSERT INTO TOPICO (titulo,mensagem, data_criacao, status, autor_id, curso_id) VALUES('Dùvida','Erro ao criar projeto', '11-01-2022', 'NAO_RESPONDIDO','1','1');