When I am running this app from IDE, it is working fine, but when app running from the command line, it gives me the following error:
http://localhost:8080/welcome
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing
this as a fallback. Thu Dec 30 21:46:01 BDT 2021 There was an
unexpected error (type=Not Found, status=404)
My controller is :
package com.example.demo;
#Controller
public class HelloController {
#RequestMapping("/welcome")
public String home() {
System.out.println("this is home page");
return "home";
}
}
application.properties
spring.mvc.view.prefix=/views/
spring.mvc.view.suffix=.jsp
Jsp file loction is :
webapp\views\home.jsp
Related
Whitelabel error in the spring boot project
Anyone give the solution for it
indexController.java
import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
#Controller
public class indexController {
#RequestMapping("index")
public String index(){
System.out.println("My Property");
return "index";
}
}
application.properties
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp
enter image description hereenter image description here
application properties are correct but i have the white lable error
Whitelabel error in the spring boot project
Anyone give the solution for it
i added enter image description here
I am following the basic Spring Boot application steps to setup the basic Spring Boot app. Have created REST controller as required. After running the application, however, I get this text on localhost:8080- "Whitelabel Error Page
This application has no explicit mapping for /error,
so you are seeing this as a fallback.
Thursday Nov 07 01:41:42 IST 2019
There was an unexpected error (type=Not Found, status=404).
No message available "
Tried adding another callback method apart from the '/' mapping, but it gives the same error.
Controller code:
#RestController
public class TestController {
#RequestMapping(value = "/")
public String home() {
return "Spring boot is working!";
}
#RequestMapping("/testing")
public String testing() {
return "Spring boot is working!";
}
Explicit #ComponentScan doesn't require if your Application class annotated with #SpringBootApplication is in root and others are sub packages of it.
Try putting in below class level annotation in your main class:
#ComponentScan(basePackages = {(name of your controller package)}
I have written a simple code for springboot with rest controller. It runs fine but does not hit the endpoint.
My Application class:
#SpringBootApplication
public class SpringbootRestTemplateDemo {
public static void main(String[] args) {
SpringApplication.run(SpringbootRestTemplateDemo.class, args);
System.out.println("Springboot Rest template demo");
}
}
My controller class:
#RestController
public class ProductController {
#RequestMapping(value="/product/details", method=RequestMethod.GET)
public String getProduct() {
return "Product details";
}
}
I expect a simple message using get request but it is not hitting the endpoint.
Input:
http://localhost:8080/product/details
output:
Whitelabel Error Page This application has no explicit mapping for
/error, so you are seeing this as a fallback.
Thu Mar 28 19:34:44 IST 2019 There was an unexpected error (type=Not
Found, status=404). No message available
We would likely need to see the folder structure to fully understand. My current guess is its possible that your main class is not in a root package above other classes.
When you run a Spring Boot Application, (i.e. a class annotated with #SpringBootApplication), Spring will only scan the classes below your main class package.
see previous answer: This application has no explicit mapping for /error
When I click on submit button I got this error message
Whitelabel Error Page This application has no explicit mapping for
/error, so you are seeing this as a fallback. Tue Jun 30 17:24:02 CST
2015 There was an unexpected error (type=Not Found, status=404). No
message available
Here is my code.
package com.tourpackage.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.tourpackage.model.TourPackage;
import com.tourpackage.repository.TourPackageMongoRepository;
import com.tourpackage.repository.VehicleTypeMongoRepository;
#Controller
public class TourPackageController {
#Autowired
TourPackageMongoRepository packageRepository;
VehicleTypeMongoRepository vehicleTypeRepository;
#RequestMapping("/tourpackage")
public String tourpackage(Model model){
model.addAttribute("packagelist", packageRepository.findAll());
return "index";
}
#RequestMapping("/addNewTour")
public String addNewTour(Model model){
model.addAttribute("packagelist", packageRepository.findAll());
return "tourpack";
}
#RequestMapping(value="/addPackage", method = RequestMethod.POST)
public String addPackage(#ModelAttribute TourPackage tourpack) {
packageRepository.save(tourpack);
return "redirect:tourpackage";
}
}
Spring Boot automatically registers the Basic ErrorController as a Spring Bean when you haven't specified an implementation for ErrorController.
so,
If you want to return customised content for path /error, refer following code:
#RestController
public class MyController implements ErrorController{
private static final String PATH = "/error";
#RequestMapping(value = PATH)
public String error() {
return "Error handling";
}
#Override
public String getErrorPath() {
return PATH;
}
}
Else,
If you want to disable it, you can refer this post:
http://www.logicbig.com/tutorials/spring-framework/spring-boot/disable-default-error-page/
The problem:
Using Spring 4, I am getting this when visiting a webpage
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Aug 15 16:41:29 BST 2014
There was an unexpected error (type=Not Found, status=404).
What I have:
I have this Main class:
// src/main/java/abc/Main.java
package abc;
import abc.web.WebAppConfig;
import org.springframework.boot.SpringApplication;
public class Main {
public static void main(String[] args) {
SpringApplication.run(WebAppConfig.class);
}
}
Then I have this WebAppConfig.class (currently with just some configuration annotations):
// src/main/java/abc/web/WebAppConfig.java
package abc.web;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
#ComponentScan
#EnableAutoConfiguration
public class WebAppConfig {
}
And this controller HomeController.java:
// src/main/java/abc/web/HomeController.java
package abc.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
#Controller
#RequestMapping("/")
public class HomeController {
#RequestMapping(method = GET)
public String home() {
System.out.println("HELLO !!");
return "home";
}
}
The HELLO !! shows up in the logs.
And finally I have a html file at src/main/java/abc/webapp/home.html, with just some html tags including a p tag with Hello, world!.
The question:
I understand that I am missing the way of rendering the view, but I searched a couple of questions on stackoverflow and haven't find a solution yet.
Can someone explain how can I get Spring to render a webpage ? What am I missing ?
Thanks in advance :)
Spring Boot will automatically use and configure Thymeleaf as the view rendering engine, as long as it's on the classpath.
To put it on the classpath use
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
in the gradle build file.
If you are using maven add the dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
In your case in order to display the home.html view (in accordance to the controller you are using), you need to place it under /resources/templates.
For a complete example, check out this guide.
The simplest answer to the "how can I get Spring Boot to render a webpage?" question is: place your home.html file inside src/main/resources/static/ folder. The page will be available under the /home.html URL.
More details in the documentation.
You probably not configured template engine and view resolver. See example with thymeleaf here http://www.thymeleaf.org/doc/thymeleafspring.html
As thymeleaf template is a valid HTML code and vice verse you can use it.