Bom dia,
Como faço para configurar o localhost na minha máquina???
Bom dia,
Como faço para configurar o localhost na minha máquina???
Oi Ludymila,
O localhost é o enderço do próprio computador e quando você rodar a aplicação com Spring Boot(rodar a classe com o método main), o próprio Spring vai subir um servidor que por padrão é executado na porta 8080. Daí basta acessar no navegador o endereço: http://localhost:8080
Bom dia Rodrigo,
Tentei rodar a aplicação, mas quando peço para rodar a classe com o método man não aparece o que está sendo construído na aula!!!
Quando abro o localhost aparece ( a sigla EDB postgres Server is up and running).
Deve ser algo como na imagem a seguir:
Isso significa que já tem outra aplicação rodando na porta 8080 do seu computador, que no caso é um servidor do banco de dados Postgres. Uma solução então é você alterar a porta da aplicação Spring Boot, adicionando a seguinte linha no arquivo src/main/application.properties:
server.port=8081
E para entrar na aplicação no navegador e nos testes durante o curso usar o endereço: http://localhost:8081
Coloquei a linha de código acima, mas não funcionou. Tem alguma outra forma?
manda um print do console do Eclipse e do navegador
Pelo print do console, nas ultimas linhas, aconteceu uma exception. Posta aqui o texto completo do console para entender o que pode ter acontecido.
2022-05-04 07:45:25.823 INFO 14864 --- [ restartedMain] br.com.alura.forum.ForumApplication : Starting ForumApplication on DESKTOP-CAEVQFB with PID 14864 (C:\Users\Rodrigo\eclipse-workspace\forum\target\classes started by Rodrigo in C:\Users\Rodrigo\eclipse-workspace\forum) 2022-05-04 07:45:25.828 INFO 14864 --- [ restartedMain] br.com.alura.forum.ForumApplication : No active profile set, falling back to default profiles: default 2022-05-04 07:45:26.396 INFO 14864 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2022-05-04 07:45:26.396 INFO 14864 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2022-05-04 07:45:32.319 INFO 14864 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode. 2022-05-04 07:45:32.817 INFO 14864 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 428ms. Found 2 repository interfaces. 2022-05-04 07:45:34.364 INFO 14864 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$7af9442a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2022-05-04 07:45:39.076 INFO 14864 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http) 2022-05-04 07:45:39.342 INFO 14864 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-05-04 07:45:39.343 INFO 14864 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17] 2022-05-04 07:45:40.103 INFO 14864 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-05-04 07:45:40.104 INFO 14864 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 13708 ms 2022-05-04 07:45:41.101 INFO 14864 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2022-05-04 07:45:42.058 INFO 14864 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2022-05-04 07:45:42.460 INFO 14864 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [ name: default
2022-05-04 07:45:43.487 INFO 14864 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.3.9.Final} 2022-05-04 07:45:43.503 INFO 14864 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found 2022-05-04 07:45:45.915 INFO 14864 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final} 2022-05-04 07:45:46.942 INFO 14864 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect 2022-05-04 07:45:48.228 WARN 14864 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.alura.forum.modelo.Resposta.Topico in br.com.alura.forum.modelo.Topico.respostas 2022-05-04 07:45:48.267 INFO 14864 --- [ restartedMain] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-199] 2022-05-04 07:45:48.268 INFO 14864 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2022-05-04 07:45:48.282 INFO 14864 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2022-05-04 07:45:48.297 INFO 14864 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2022-05-04 07:45:48.355 INFO 14864 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2022-05-04 07:45:48.397 ERROR 14864 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.alura.forum.modelo.Resposta.Topico in br.com.alura.forum.modelo.Topico.respostas at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.alura.forum.modelo.Resposta.Topico in br.com.alura.forum.modelo.Topico.respostas at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at br.com.alura.forum.ForumApplication.main(ForumApplication.java:10) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.1.4.RELEASE.jar:2.1.4.RELEASE]
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.alura.forum.modelo.Resposta.Topico in br.com.alura.forum.modelo.Topico.respostas at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:785) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final] at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:736) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final] at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1696) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1664) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:287) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final] at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] ... 21 common frames omitted
O erro: Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.alura.forum.modelo.Resposta.Topico in br.com.alura.forum.modelo.Topico.respostas
Foi algum errinho na hora de adicionar as anotações da JPA nas entidades. Posta aqui o código das suas classes Topico
e Resposta
Rodrigo,
boa tarde !!! Conseguir consertar o erro acima que vc falou, mas agora nessa classe quando coloco o map(resposta::new) não roda de forma alguma.
package br.com.alura.forum.controller.dto;
import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors;
import br.com.alura.forum.modelo.Resposta; import br.com.alura.forum.modelo.StatusTopico; import br.com.alura.forum.modelo.Topico;
public class DetalhesTopicoDto {
private Long id;
private String titulo;
private String mensagem;
private LocalDateTime dataCriacao;
private String nomeAutor;
private StatusTopico status;
private List<RespostaDto> respostas;
public DetalhesTopicoDto(Topico topico) {
this.id = topico.getId();
this.titulo = topico.getTitulo();
this.mensagem = topico.getMensagem();
this.dataCriacao = topico.getDataCriacao();
this.nomeAutor = topico.getAutor().getNome();
this.status = topico.getStatus();
this.respostas = new ArrayList<>();
this.respostas.addAll(topico.getRespostas().stream(). map(Resposta::new)).collect(Collectors.toList()));
}
public Long getId() {
return id;
}
public String getTitulo() {
return titulo;
}
public String getMensagem() {
return mensagem;
}
public LocalDateTime getDataCriacao() {
return dataCriacao;
}
public String getNomeAutor() {
return nomeAutor;
}
public StatusTopico getStatus() {
return status;
}
public List<RespostaDto> getRespostas() {
return respostas;
}
}
Na verdade nesse trecho dessa linha o correto é: RespostaDto::new