0

I don´t have any idea if it´s missing something for this to start work. I´ve created all enviroment and system variables, downloaded repository, downloaded and configured the database and finally when I tried my "Hello Word" it didn´t work. Never sttoped at the breakpoint either.

I have one simple controller with a method

@Controller
public class HomeController {

@RequestMapping("/")
@ResponseBody
public  String  index() {
    System.out.println("Log");
    return "Welcome!";
}

}

my properties has only this

#   data    source

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/fj27_spring? 
createDatabaseIfNotExist=true&useSSL=false&allowPublicKeyRetrieval=true&useTimezone=true&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=xxxxxx

#   jpa properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true

and when I run my application I got this

2020-07-13 15:28:48.537  INFO 16524 --- [           main] com.example.teste.TesteApplication       : 
Started TesteApplication in 3.411 seconds (JVM running for 4.086)
2020-07-13 15:28:48.797  INFO 16524 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : 
HikariPool-1 - Start completed.
2020-07-13 15:28:48.819  INFO 16524 --- [         task-1] org.hibernate.dialect.Dialect            : 
HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
2020-07-13 15:28:49.171  INFO 16524 --- [         task-1] o.h.e.t.j.p.i.JtaPlatformInitiator       : 
HHH000490: Using JtaPlatform implementation: 
[org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-07-13 15:28:49.179  INFO 16524 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : 
Initialized JPA EntityManagerFactory for persistence unit 'default'

So everything seems ok, but when I run my application and open http://localhost:8080/, I never get there, it never goes to the controller to put the message, the front gives me a return of 404 and the default spring error page. I don´t know if it´s something I missed because the error only appears when I open the page, not on compiling, building or when it´s starting running. I get the 404 but the Eclipse Console got nothing new.

2 Answers2

0

Try to define the server.servlet.context-path=/demo in the application.properties. Then access the endpoint use url : http://localhost:8080/demo/. I think your problem will get resolve.

MadProgrammer
  • 513
  • 5
  • 18
  • I tried that but the problem keeps the same...he recognized the change of the path, but I still got a 404 -- 2020-07-14 09:29:27.536 INFO 9448 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/demo' – Rafael Perracini Jul 14 '20 at 12:41
0

I guess you are missing scanBasePackages and also make sure your HomeController class or other controller classes are in package com.example.teste or if its is another package then make sure you add package name it in scanBasePackages. Please update your code as below

@SpringBootApplication(scanBasePackages = "com.example.teste")
public class TesteApplication {
 public static void main(String[] args) {
  SpringApplication.run(TesteApplication.class, args);
 }
}