• Register
0 votes
4.5k views

Problem :

I am trying to write Spring boot code
The Program is running but I am getting following error:

This application has no explicit mapping for /error, so you are seeing this as a fallback.    

How to fix this error?

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

When we are creating a Spring boot application we must annotate it with @SpringBootApplication annotation. This annotation will 'wrap up' many other necessary annotations for the application to work smoothly without errors. One such annotation as @ComponentScan annotation .Use of this annotation is to tell the Spring to look for all required Spring components and configure the application to run smoothly.

Application class must be present at the top of your package hierarchy, to allow Spring to scan sub-packages and look for the other required components.

Please find the sample code for your reference as follows:

package com.test.spring.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}

Following code snippet works like the controller package is under com.test.spring.boot package

package com.test.spring.boot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyHomeController {
    @RequestMapping("/")
    public String myhome(){
        return "Hello World!";
    }
}

Following code snippet will NOT Work as the controller package as it is NOT under com.test.spring.boot package

package com.test.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyHomeController {
     @RequestMapping("/")
     public String myhome(){
         return "Hello World!";
     }
 }

 

If you follow above given approach your issue will be resolved.

9 7 4
38,600 points

Related questions

0 votes
1 answer 42 views
42 views
Problem : I am trying to write Spring boot code The Program is running but I am getting following error: This application has no explicit mapping for /error, so you are seeing this as a fallback. How to fix this error?
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 93 views
93 views
Problem unable to process parts as no multi-part configuration has been provided
asked Feb 9 charles mathews 5.5k points
0 votes
1 answer 2 views
2 views
Problem: Do you have any suggestions about how I would be able to resolve this issue?
asked 2 days ago zayed1 35.6k points
0 votes
1 answer 13 views
13 views
Problem: could anybody help me to fix this ? Could not extract response: no suitable httpmessageconverter found for response type.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.9K views
2.9K views
Problem : I am trying to use the curl command as follows: curl -u 591bf65f50057469f10b5fd9:0cf17f9b03d056ds0e11e48497e506a2 https://backend.tdk.com/api/devicetypes/59147fd79e93s12e61499ffe/messages But I am getting a JSON response as follows: {"data":[{"device":"18SE62"," ... T>, Object...) in the type RestTemplate is not applicable for the arguments (String, HttpEntity<String>,Class<MessageList>)
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 5 views
5 views
Problem: Is anyone available to assist me and resolve this issue? java.lang.illegalstateexception: cannot call senderror() after the response has been committed
asked Apr 7 Ifra 24.4k points
0 votes
2 answers 723 views
723 views
Problem : I am new to the Spring and JPA, wasted 10 days and no result with the searching on internet. I want to save the object to SQL SERVER, my connection is correct but when I write .flush() I get below exception &ldquo;nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress&rdquo;
asked Jan 21, 2020 jwilliam 3.9k points
0 votes
2 answers 293 views
293 views
Problem : I have created entities, services and JUnit tests for services using Spring and Hibernate for my project. All of these are working. After that I added spring-mvc to it to make this web application but while trying to make ... follows ..Could not autowire field: public pl.com.radzikowski.webmail.service.IMailManager pl.com.radzikowski.webmail.controller.HomeController.mailManager...
asked Nov 20, 2019 peterlaw 6.9k points
0 votes
1 answer 392 views
392 views
Problem : I am new to Spring and JPA I want to save object to SQL SERVER, connection is correct but when I write .flush() I get the exception as below javax.persistence.TransactionRequiredException: no transaction is in progress
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
1 answer 15 views
15 views
Problem: I need help in solving this error: Could not obtain transaction-synchronized session for current thread.
asked Mar 13 Wafa Abu Yousef 6.1k points