I have this simple java Spring Boot project without any beans or persistency. I've created multiple packages to separate classes by functionality.
I read that controllers must be inside initial package NameApplication.java. However, I launch project on port 8080 and put next url localhost:8080/hello/grettings show me Whitelabel Error Page but I put localhost:8080 and load index.html
Why doesn't work?
@Controller
@RequestMapping("/hello")
public class BasicController {
@GetMapping(path = {"/grettings", "/helloworld"})
public String grettings() {
return "index";
}
}
application.properties
# Application name.
spring.application.name=CursoSpring
# Logging
logging.level.root=WARN
logging.level.com.globalomnium=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
#Flyway
#spring.flyway.baseline-on-migrate=true
# THYMELEAF
#spring.thymeleaf.check-template-location=true
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html
#spring.thymeleaf.mode=HTML
#spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
# Server HTTP port.
server.port=8080
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
Package structure
CursoSpringApplication is the starting point of the application. when starting it searches for components such as @Controller, @Service, @Repository and @Component. Usually recommend that you locate your main application class in a root package above other classes. So this CursoSpringApplication class should be placed in most outer package. Change com.globalomnium.axis.maps
to com.globalomnium.axis
Example Structure
com
+- example
+- myapplication
+- Application.java
|
+- customer
| +- Customer.java
| +- CustomerController.java
| +- CustomerService.java
| +- CustomerRepository.java
|
+- order
+- Order.java
+- OrderController.java
+- OrderService.java
+- OrderRepository.java