13
respostas

Erro ao gerar senha criptografada

Meu INSERT: INSERT INTO USUARIO(nome, email, senha) VALUES('Aluno', 'aluno@email.com', '$2a$10$Jb6q/7yDi82mDXyrN8MMje0N0VWmGNQbSQOQtysYqlBjIAFN7uSa2');

Realizei o processo identico ao do professor e ao rodar o projeto apareceu o erro

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/diogocarpio/Downloads/forum/forum/target/classes/data.sql]: INSERT INTO USUARIO(nome, email, senha) VALUES('Aluno', 'aluno@email.com', '$2a$10$Jb6q/7yDi82mDXyrN8MMje0N0VWmGNQbSQOQtysYqlBjIAFN7uSa2'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USUARIO" not found; SQL statement: INSERT INTO USUARIO(nome, email, senha) VALUES('Aluno', 'aluno@email.com', '$2a$10$Jb6q/7yDi82mDXyrN8MMje0N0VWmGNQbSQOQtysYqlBjIAFN7uSa2') [42102-200] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.8.jar:5.3.8]

13 respostas

O Erro foi: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USUARIO" not found;

As tabelas nao foram criadas.

Da uma olhada nesse topico: https://cursos.alura.com.br/forum/topico-tabelas-nao-criadas-162200

Beleza, eu vi o topico e ja adicionei o que foi pedido.

Porém apareceu o seginte erro agora

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-06-24 14:18:07.515 ERROR 15104 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfigurations': Unsatisfied dependency expressed through field 'tokenService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'forum.jwt.expiration' in value "${forum.jwt.expiration}" at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.3.8.jar:5.3.8] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.3.8.jar:5.3.8]

Verifica se no seu arquivo application.properties tem a propriedade forum.jwt.expiration, pois pelo erro ta faltando essa propriedade

jwt - autenticação token

forum.jwt.secret=rm'!@N=Ke!p8VTA2ZRKnMDQX5Uvm!m'D&]{@Vr?G;2?XhbC:Qa#9#eMLN}x3?JR3.2zrv)gYF^8:8>:XfB:Ww75N/emt9Yj[bQMNCWwW\J?N,nvH.<2.rw]e~vgak)X"v8HMH/7"2E,^k@n<vE-wD3g9JWPy;CrY.Kd2_D])=><D?YhBaSua5hW%{2]_FVXzb98FH^b[X3jzVER&:jw2<=c38=>L/zBq}C6tT*cCSVC^c]-L}&/

forum.jwt.expiration=86400000

Eu fiz identico ao que você passou nas aulas e copiei e colei no application.properties

Pode ser entao por conta de algum caractere especial na senha do forum.jwt.secret que esta causando erro e ele nao le a ultima linha que tem o forum.jwt.expiration

Faz um teste, coloca essa propriedade da senha(forum.jwt.secret) na ultima linha do arquivo

fiz o processo assim como pediu

jwt - autenticação token

forum.jwt.expiration=86400000

forum.jwt.secret=rm'!@N=Ke!p8VTA2ZRKnMDQX5Uvm!m'D&]{@Vr?G;2?XhbC:Qa#9#eMLN}x3?JR3.2zrv)gYF^8:8>:XfB:Ww75N/emt9Yj[bQMNCWwW\J?N,nvH.<2.rw]e~vgak)X"v8HMH/7"2E,^k@n<vE-wD3g9JWPy;CrY.Kd2_D])=><D?YhBaSua5hW%{2]_FVXzb98FH^b[X3jzVER&:jw2<=c38=>L/zBq}C6tT*cCSVC^c]-L}&/

depois no projeto eu cliquei com o botão direito/ maven/ update project

O erro continua

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfigurations': Unsatisfied dependency expressed through field 'tokenService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'forum.jwt.expiration' in value "${forum.jwt.expiration}"

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'forum.jwt.expiration' in value "${forum.jwt.expiration}"

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'forum.jwt.expiration' in value "${forum.jwt.expiration}"

Atualizei no proximo comentario...

Entao pode ser por conta do profile.

Verifica qual profile esta sendo carregado quando voce roda o projeto.

Atualizando...

O erro da tag

`<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>`

Como assim profile? pode me ensinar como vejo isso.

Uma duvida rapida que percebi aqui

minha senha no data.sql =

INSERT INTO USUARIO(nome, email, senha) VALUES('Aluno', 'aluno@email.com', '$2a$10$Jb6q/7yDi82mDXyrN8MMje0N0VWmGNQbSQOQtysYqlBjIAFN7uSa2');

no application.properties

forum.jwt.secret=rm'!@N=Ke!p8VTA2ZRKnMDQX5Uvm!m'D&]{@Vr?G;2?XhbC:Qa#9#eMLN}x3?JR3.2zrv)gYF^8:8>:XfB:Ww75N/emt9Yj[bQMNCWwW\J?N,nvH.<2.rw]e~vgak)X"v8HMH/7"2E,^k@n<vE-wD3g9JWPy;CrY.Kd2_D])=><D?YhBaSua5hW%{2]_FVXzb98FH^b[X3jzVER&:jw2<=c38=>L/zBq}C6tT*cCSVC^c]-L}&/

As duas informações precisam ser identicas ?