As with any web application or website, Spring MVC returns the HTTP 404 response code when the requested resource can't be found.
Run the Spring Boot application For running the Spring Boot application, open the main application file, and run it as Java Application. When the application runs successfully, it shows the message in the console, as shown below. Now, open the browser and invoke the URL http://localhost:8080.
Another way of disabling the WhiteLabel Error is excluding the ErrorMvcAutoConfiguration . Alternatively, the exclusion can be done in an annotation. When the WhiteLabel Error Page is disabled and no custom error page is provided, the web server's error page (Tomcat, Jetty) is shown.
Try adding the following to your InventoryApp class
@SpringBootApplication
@ComponentScan(basePackageClasses = ItemInventoryController.class)
public class InventoryApp {
...
spring-boot will scan for components in packages below com.nice.application
, so if your controller is in com.nice.controller
you need to scan for it explicitly.
Adding to MattR's answer:
As stated in here, @SpringBootApplication
automatically inserts the needed annotations: @Configuration
, @EnableAutoConfiguration
, and also @ComponentScan
; however, the @ComponentScan
will only look for the components in the same package as the App, in this case your com.nice.application
, whereas your controller resides in com.nice.controller
. That's why you get 404 because the App didn't find the controller in the application
package.
Same 404 response I got after service executed with the below code
@Controller
@RequestMapping("/duecreate/v1.0")
public class DueCreateController {
}
Response:
{
"timestamp": 1529692263422,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/duecreate/v1.0/status"
}
after changing it to below code I received proper response
@RestController
@RequestMapping("/duecreate/v1.0")
public class DueCreateController {
}
Response:
{
"batchId": "DUE1529673844630",
"batchType": null,
"executionDate": null,
"status": "OPEN"
}
SpringBoot developers recommend to locate your main application class in a root package above other classes. Using a root package also allows the @ComponentScan annotation to be used without needing to specify a basePackage attribute. Detailed info But be sure that the custom root package exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With