【问题标题】:This application has no explicit mapping for /error此应用程序没有 /error 的显式映射
【发布时间】:2015-09-17 00:25:06
【问题描述】:

我用maven做教程https://spring.io/guides/gs/uploading-files/
我使用的所有代码都被复制了。

应用程序可以运行,但出现错误:

Whitelabel 错误页面 此应用程序没有显式映射 /error,因此您将其视为后备。 2015 年 6 月 30 日星期二 17:24:02 CST 出现意外错误(类型=未找到,状态=404)。 没有可用的消息

我该如何解决?

【问题讨论】:

    标签: spring spring-mvc file-upload upload


    【解决方案1】:

    我最近遇到了同样的问题。我已经通过getter和setter方法拼写更正解决了!

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案2】:

    添加 devtools 依赖,这将启用 H2ConsoleAutoConfiguration。

     <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
            </dependency>
    

    在日志中您可以看到以下行:

    o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:my-app'
    

    然后尝试访问

    http://localhost:8080/h2-console/
    

    【讨论】:

      【解决方案3】:

      这个错误发生在我身上,

      因为控制器文件(在 restfortest 包中)不在 Application.java (SpbdemoApplication) 文件目录中。

      为了解决这个问题,

      1. 你可以把restfortest包作为子包,比如rest包 如下图所示。

      2.否则你可以编辑application.java文件如下图。

      出现此错误是因为@SpringBootApplication 告诉 Spring 查找 Spring 组件并配置应用程序以运行。如果没有放在同一个包中,spring 看不到控制器类(在此处 com.pj.lerningcurve.spddemo)

      【讨论】:

        【解决方案4】:

        除了上面所有很酷的答案。只需检查该方法的请求映射是否可用。这是一个示例代码。

        @RestController
        @RequestMapping("api/v1/data")
        public class SampleController {
        
          private final SampleService sampleService;
        
          @Autowired
          public SampleController(SampleService sampleService) {
            this.sampleService= sampleService;
          }
        
          @GetMapping
          public List<SimpleData> getData() {
            return sampleService.getData();
          }
        }
        

        您可能会忘记将@GetMapping 添加到getData 方法中。

        【讨论】:

          【解决方案5】:

          我在学习 spring HATEOAS 时遇到了这个问题。我检查了上面给出的所有答案,但问题没有解决。最后,我将我的控制器类粘贴到“main application.java”包中,它对我有用。[![你可以在图片中看到我在一个包中添加了我的控制器类和主类。您还可以在同样适用于我的包中添加“模型类、主类和控制器类”。在下图中,我在同一个包中添加了控制器和主类。

          【讨论】:

            【解决方案6】:

            我正在开发 Spring Boot 应用程序几个星期。我遇到了同样的错误,如下所示;

            白标错误页面 此应用程序没有显式映射 /error,因此您将其视为后备。 2018 年 1 月 18 日星期四 14:12:11 AST 出现意外错误(类型=未找到,状态=404)。 没有可用的消息

            当我收到此错误消息时,我意识到我的控制器或休息控制器类未在我的项目中定义。 我的意思是我们所有的控制器包都与包含 @SpringBootApplication 注释的主类不同。 我的意思是您需要将控制器包的名称添加到包含 @ 的主类的 @ComponentScan 注释中SpringBootApplication 注解。如果您编写下面的代码,您的问题将得到解决... 最重要的是您必须像我在下面所做的那样将所有控制器的包添加到 @ComponentScan 注释

            package com.example.demo;
            
            import org.springframework.boot.SpringApplication;
            import org.springframework.boot.autoconfigure.SpringBootApplication;
            import org.springframework.context.annotation.ComponentScan;
            
            @SpringBootApplication
            @ComponentScan({ "com.controller.package1, com.controller.package2, com.controller.package3, com.controller.packageN", "controller", "service" } // If our Controller class or Service class is not in the same packages we have //to add packages's name like this...directory(package) with main class
            public class MainApp {
                public static void main(String[] args) {
                    SpringApplication.run(MainApp.class, args);
                }
            }
            

            我希望这些代码能对某人有所帮助...

            如果您找到解决此错误的其他方法或者您对我有一些建议, 请写信给 cmets...谢谢...

            【讨论】:

              【解决方案7】:

              我遇到了类似的问题。我在所有控制器的顶部都有 Main.class,但我遇到了这个问题。我需要做的就是创建一个单独的 swagger 配置文件并在其中初始化 docket bean。

              注意:该文件的位置应该在 Main.class 文件的同一个包中或在该主包内的包中。

              SwaggerConfiguration.java 文件

              package com.example.springDataJPAUsingGradle;
              
              import org.springframework.context.annotation.Bean;
              import org.springframework.context.annotation.Configuration;
              
              import springfox.documentation.spi.DocumentationType;
              import springfox.documentation.spring.web.plugins.Docket;
              import springfox.documentation.swagger2.annotations.EnableSwagger2;
              
              @Configuration
              @EnableSwagger2
              public class SwaggerConfig {
                  @Bean
                  public Docket docket() {
                      return new Docket(DocumentationType.SWAGGER_2).select().build();
                  }
              }
              

              我还必须在我的 controller.java 中添加 @RequestMapping("/api")。 方法如下:

              package com.example.springDataJPAUsingGradle.controller;
              
              import org.springframework.beans.factory.annotation.Autowired;
              import org.springframework.web.bind.annotation.GetMapping;
              import org.springframework.web.bind.annotation.RequestBody;
              import org.springframework.web.bind.annotation.RequestMapping;
              import org.springframework.web.bind.annotation.RestController;
              
              import com.example.springDataJPAUsingGradle.service.StudentService;
              
              @RestController
              @RequestMapping("/api")
              public class StudentController {
              
                  @Autowired(required = true)
                  @GetMapping("/home")
                  public String home() {
                      return "Welcome to home page";
                  }
              }
              

              然后在点击 url 后:http://localhost:9090/your-app-root/swagger-ui/ swagger UI 将可见。 例如,在我的情况下,网址是:http://localhost:9090/students/swagger-ui/

              【讨论】:

                【解决方案8】:

                在我的情况下,我遇到了这个问题,因为我的服务器已经在执行 UploadingFilesApplication.java(带有 @SpringBootApplication 注释的文件)时运行。

                我通过执行FileUploadController.java(带有@Controller 注释的文件)简单地重新运行服务器来解决此问题。

                【讨论】:

                  【解决方案9】:

                  您的 pom.xml 文件中可能没有包含 thymleaf。

                  【讨论】:

                    【解决方案10】:

                    我在为我的 Web 应用程序使用 Keycloak 身份验证时遇到此错误。我找不到关于 Keycloak 的答案,所以想发帖,因为它可以帮助其他人。

                    我收到了这个错误

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

                    因为我在 Java 应用程序资源的 application.properties 文件中使用了属性 keycloak.bearer-only=true。这将确保无法从浏览器进行登录,因此我们需要使用令牌。我删除了这条命令,它在浏览器中运行。

                    如果您使用命令keycloak.bearer-only=true 并尝试使用浏览器访问应用程序,那么您可能会遇到同样的问题。

                    【讨论】:

                      【解决方案11】:

                      确保在@SpringBootApplication 之后添加@RestController 注解。 RestController 注解告诉 Spring 这段代码描述了一个应该在 web 上可用的端点。

                      【讨论】:

                        【解决方案12】:

                        主类需要在您的应用程序包树结构之外。例如:

                        【讨论】:

                          【解决方案13】:

                          如果所有配置都正确完成(如本问题前两到三个答案中所述),您仍然收到“Whitelabel Error Page”此应用程序没有/error 的显式映射,那么此解决方案可能会对您有所帮助

                          有时除了配置之外,问题也可能来自您的代码方面。 您可能错过了一些非常基本的内容。
                          要确定问题,您需要检查跟踪,请按照以下步骤操作

                          打开终端。
                          1)cd project_location,获取项目位置。
                          例如eclipse->项目(右键单击)->属性->资源(选项卡)->根据位置字段复制路径。
                          2)然后运行脚本 ./mvnw spring-boot:run

                          然后转到http://localhost:8080/http://localhost:8080/xyz 任何您期望数据的网址。只要您点击链接,跟踪就会得到更新。

                          我遇到了类似的错误
                          2020-05-23 06:52:42.405 错误 3512 --- [nio-8080-exec-1] oaccC[.[.[/].[dispatcherServlet]:Servlet.service()带有路径 [] 的上下文中的 servlet [dispatcherServlet] 引发异常 [请求处理失败;嵌套异常是 org.springframework.orm.jpa.JpaSystemException: No default constructor for entity: : com.ibsplc.com.payroll.model.Employee;嵌套异常是 org.hibernate.InstantiationException: No default constructor for entity: : com.ibsplc.com.payroll.model.Employee] with root cause

                          所以,我为 Employee 模型添加了一个默认构造函数。 将项目作为 maven-build 运行 然后运行脚本 ./mvnw spring-boot:run,
                          它对我有用

                          【讨论】:

                            【解决方案14】:

                            默认情况下,spring boot 会扫描当前包中的 bean 定义。因此,如果您当前定义了主类的包和控制器包不同,或者控制器包不是您的主应用程序包的子包,它将不会扫描控制器。为了解决这个问题,可以在主包中包含 bean 定义的包列表

                            @SpringBootApplication(scanBasePackages = {"com.module.restapi1.controller"})
                            

                            或创建一个包的层次结构,其中子包派生自主包

                            package com.module.restapi;
                            package com.module.restapi.controller
                            

                            【讨论】:

                            • 这里是 IMO 的最佳答案之一,因为如果您不想(或不能)重新排列包裹,它会为您提供有关如何扫描以提供控制器的指导。谢谢!
                            【解决方案15】:

                            我需要以这种方式提及并提供对包的引用,并且成功了。您可以排除 @EnableAutoConfiguration 此注释,但我需要绕过任何与数据库相关的依赖项。

                            @SpringBootApplication
                            @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
                            @ComponentScan(basePackages = {"your package 1", "your package2"})
                            
                            public class CommentStoreApplication {
                            
                                public static void main(String[] args) {
                                    SpringApplication.run(CommentStoreApplication.class, args);
                            
                                }
                            }
                            

                            【讨论】:

                              【解决方案16】:

                              聚会迟到了。根据 Spring 官方文档“Spring Boot 会安装一个白标签错误页面,如果您遇到服务器错误,您会在浏览器客户端中看到该页面。” https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-customize-the-whitelabel-error-page

                              1. 您可以通过在 application.ymlapplication.properties 文件中设置 server.error.whitelabel.enabled=false 来禁用该功能。

                              2.推荐方式设置您的错误页面,以便最终用户能够理解。在 resources/templates 文件夹下创建一个 error.html 文件并在 pom.xml 文件中添加依赖项

                              <dependency>
                              <groupId>org.springframework.boot</groupId>
                              <artifactId>spring-boot-starter-thymeleaf</artifactId>
                              </dependency>
                              

                              Spring 会自动选择 error.html 页面作为默认的错误模板。 注意:- 添加依赖后不要忘记更新maven项目。

                              【讨论】:

                              • 不!您假设每个人都在使用或想要使用百里香。还有其他模板引擎。所以这不是一个好的解决方案
                              【解决方案17】:

                              确保你的依赖列表中有jasper和jstl:

                              <dependency>
                                  <groupId>org.apache.tomcat.embed</groupId>
                                  <artifactId>tomcat-embed-jasper</artifactId>
                                  <scope>provided</scope>
                              </dependency>
                              <dependency>
                                  <groupId>javax.servlet</groupId>
                                  <artifactId>jstl</artifactId>
                              </dependency>

                              这是一个有效的入门项目 - https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp

                              作者:Biju Kunjummen

                              【讨论】:

                              • 这是做什么的?
                              【解决方案18】:

                              您必须组织这些包,以便包含公共静态 main(或您编写 @SpringBootApplication 的地方)的包,这是您所有其他包的父亲。

                              【讨论】:

                              • - com.mypackage +nameApplication.java - com.mypachage.model - com.mypachage.controller - com.mypachage.dao
                              【解决方案19】:

                              如果你已经用 requestMapping 注释了接口,请确保你也用@Component 注释了实现接口的类。

                              【讨论】:

                              • 欢迎来到stackoverflow。已经有很多关于这个问题的答案 - 请扩展您的答案,以便清楚您提供了哪些新细节。
                              【解决方案20】:

                              当你的 spring 应用程序无法找到 spring 组件并且它没有在 sprint 容器中初始化时,有时会发生这种情况,你可以使用 @ComponentScan 和 @SpringBootApplication 添加组件,如下例所示

                              @SpringBootApplication
                              @ComponentScan({"model", "service"})
                              class MovreviewApplication {
                              
                                              public static void main(String[] args) {
                                      SpringApplication.run(MovreviewApplication.class, args);
                              
                              }
                              

                              在上面的示例模型和服务是我的应用程序中的包。

                              【讨论】:

                                【解决方案21】:

                                我在尝试使用 Thymeleaf 的 Spring Boot 示例应用程序时遇到了类似的错误,尝试了提供的所有不同解决方案,但不幸的是没有奏效。

                                我的错误是控制器方法返回的字符串没有相应的视图 html。

                                可能是您遗漏了文件名或文件名中存在拼写错误。 如控制器内部示例所示

                                @GetMapping("/")
                                public String listUploadedFiles(Model model) throws IOException {
                                
                                    model.addAttribute("files", storageService.loadAll().map(
                                            path -> MvcUriComponentsBuilder.fromMethodName(FileUploadController.class,
                                                    "serveFile", path.getFileName().toString()).build().toString())
                                            .collect(Collectors.toList()));
                                
                                    return "uploadForm";
                                }
                                

                                返回的字符串应该与 html 文件名匹配

                                src/main/resources/templates/uploadForm.html

                                Thymeleaf 将寻找与返回类型同名的文件并显示视图。您可以尝试使用任何 html 文件并在 return 语句中给出文件名,它将填充相应的视图。

                                【讨论】:

                                  【解决方案22】:

                                  请确保您没有将视图、JSP 或 HTML 放在 WEB-INF 或 META-INF 中

                                  请仔细提及这些细节:

                                  spring.mvc.view.prefix
                                  spring.mvc.view.suffix
                                  

                                  【讨论】:

                                    【解决方案23】:

                                    使用 Spring Boot 和 application.properties 文件,我不得不更改项目的结构。 JSP 文件应位于以下位置: \src\main\resources\META-INF\resources\WEB-INF\jsp. 在此更改后,我的项目有效。 我在这里找到了解决方案:https://www.logicbig.com/tutorials/spring-framework/spring-boot/boot-serve-dynamic.html

                                    【讨论】:

                                      【解决方案24】:

                                      如果您忘记了控制器类顶部的@RestController 注解,就会发生这种情况 import import org.springframework.web.bind.annotation.RestController;

                                      并添加如下注释

                                      参考下面的简单例子

                                      import org.springframework.web.bind.annotation.RestController;
                                      import org.springframework.web.bind.annotation.RequestMapping;
                                      
                                      
                                      @RestController
                                      public class HelloController {
                                      @RequestMapping("/")
                                          public String index() {
                                              return "Greetings from Spring Boot!";
                                          }
                                      
                                      }
                                      

                                      【讨论】:

                                        【解决方案25】:

                                        在教程中,控制器使用@Controller 注解,用于创建模型对象的 Map 并查找视图,但 @RestController 只是简单地返回对象,对象数据直接以 JSON 或 XML 形式写入 HTTP 响应。 如果要查看响应,请使用 @RestController 或将 @ResponseBody 与 @Controller 一起使用。

                                        @Controller
                                        @ResponseBody
                                        

                                        阅读更多:https://javarevisited.blogspot.com/2017/08/difference-between-restcontroller-and-controller-annotations-spring-mvc-rest.html#ixzz5WtrMSJHJ

                                        【讨论】:

                                          【解决方案26】:

                                          当未定义显式错误页面时会发生这种情况。要定义错误页面,请使用视图创建 /error 的映射。 例如下面的代码映射到发生错误时返回的字符串值。

                                          package com.rumango.controller;
                                          
                                          import org.springframework.boot.web.servlet.error.ErrorController;
                                          import org.springframework.stereotype.Controller;
                                          import org.springframework.web.bind.annotation.RequestMapping;
                                          import org.springframework.web.bind.annotation.ResponseBody;
                                          @Controller
                                          public class IndexController implements ErrorController{
                                              private final static String PATH = "/error";
                                              @Override
                                              @RequestMapping(PATH)
                                              @ResponseBody
                                              public String getErrorPath() {
                                                  // TODO Auto-generated method stub
                                                  return "No Mapping Found";
                                              }
                                          
                                          }
                                          

                                          【讨论】:

                                          • 你能在你的代码中添加一些解释吗?为什么它解决了问题,哪些是关键部分?
                                          • 在这个答案中,与 Spring Boot 相关的一个具体的事情一开始让我有点头疼。实现springframework的ErrorController接口很重要。如果您创建一个映射到“/error”的控制器端点而不这样做,您将收到一个错误,告诉您该方法已被映射。
                                          【解决方案27】:

                                          我遇到了这个问题,后来意识到我在 MvcConfig 类中缺少 @Configuration 注释,该类基本上为 ViewControllerssetViewNames 进行映射。

                                          这是文件的内容:

                                          import org.springframework.context.annotation.Configuration;
                                          import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
                                          import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
                                          **@Configuration**
                                          public class MvcConfig implements WebMvcConfigurer{
                                             public void addViewControllers(ViewControllerRegistry registry)
                                             {
                                                registry.addViewController("/").setViewName("login");
                                                registry.addViewController("/login").setViewName("login");
                                                registry.addViewController("/dashboard").setViewName("dashboard");
                                             }
                                          }
                                          

                                          希望这对某人有帮助!

                                          【讨论】:

                                          • 这是为我做的。
                                          【解决方案28】:

                                          当我们创建一个 Spring Boot 应用程序时,我们使用 @SpringBootApplication 注释对其进行注释。此注释“包装”了许多其他必要的注释,以使应用程序正常工作。一种这样的注释是@ComponentScan 注释。这个注解告诉 Spring 寻找 Spring 组件并配置应用程序运行。

                                          您的应用程序类需要位于包层次结构的顶部,以便 Spring 可以扫描子包并找出其他所需的组件。

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

                                          下面的代码 sn -p works 因为控制器包在com.test.spring.boot 包下

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

                                          下面的代码 sn-p 不起作用因为控制器包不在com.test.spring.boot 包下

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

                                          来自 Spring Boot 文档:

                                          许多 Spring Boot 开发人员总是对他们的主类进行注解 与@Configuration@EnableAutoConfiguration@ComponentScan。 由于这些注释经常一起使用(尤其是如果 你遵循上面的最佳实践),Spring Boot 提供了一个 方便@SpringBootApplication替代。

                                          @SpringBootApplication 注解等价于使用 @Configuration@EnableAutoConfiguration@ComponentScan 与他们的 默认属性

                                          【讨论】:

                                            【解决方案29】:

                                            您可以通过在应用程序中添加ErrorController 来解决此问题。您可以让错误控制器返回您需要的视图。

                                            我的应用程序中的错误控制器如下所示:

                                            import org.springframework.boot.autoconfigure.web.ErrorAttributes;
                                            import org.springframework.boot.autoconfigure.web.ErrorController;
                                            import org.springframework.http.HttpStatus;
                                            import org.springframework.http.ResponseEntity;
                                            import org.springframework.stereotype.Controller;
                                            import org.springframework.web.bind.annotation.RequestMapping;
                                            import org.springframework.web.bind.annotation.ResponseBody;
                                            import org.springframework.web.context.request.RequestAttributes;
                                            import org.springframework.web.context.request.ServletRequestAttributes;
                                            import org.springframework.web.servlet.ModelAndView;
                                            
                                            import javax.servlet.http.HttpServletRequest;
                                            import java.util.Map;
                                            
                                            /**
                                             * Basic Controller which is called for unhandled errors
                                             */
                                            @Controller
                                            public class AppErrorController implements ErrorController{
                                            
                                                /**
                                                 * Error Attributes in the Application
                                                 */
                                                private ErrorAttributes errorAttributes;
                                            
                                                private final static String ERROR_PATH = "/error";
                                            
                                                /**
                                                 * Controller for the Error Controller
                                                 * @param errorAttributes
                                                 */
                                                public AppErrorController(ErrorAttributes errorAttributes) {
                                                    this.errorAttributes = errorAttributes;
                                                }
                                            
                                                /**
                                                 * Supports the HTML Error View
                                                 * @param request
                                                 * @return
                                                 */
                                                @RequestMapping(value = ERROR_PATH, produces = "text/html")
                                                public ModelAndView errorHtml(HttpServletRequest request) {
                                                    return new ModelAndView("/errors/error", getErrorAttributes(request, false));
                                                }
                                            
                                                /**
                                                 * Supports other formats like JSON, XML
                                                 * @param request
                                                 * @return
                                                 */
                                                @RequestMapping(value = ERROR_PATH)
                                                @ResponseBody
                                                public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
                                                    Map<String, Object> body = getErrorAttributes(request, getTraceParameter(request));
                                                    HttpStatus status = getStatus(request);
                                                    return new ResponseEntity<Map<String, Object>>(body, status);
                                                }
                                            
                                                /**
                                                 * Returns the path of the error page.
                                                 *
                                                 * @return the error path
                                                 */
                                                @Override
                                                public String getErrorPath() {
                                                    return ERROR_PATH;
                                                }
                                            
                                            
                                                private boolean getTraceParameter(HttpServletRequest request) {
                                                    String parameter = request.getParameter("trace");
                                                    if (parameter == null) {
                                                        return false;
                                                    }
                                                    return !"false".equals(parameter.toLowerCase());
                                                }
                                            
                                                private Map<String, Object> getErrorAttributes(HttpServletRequest request,
                                                                                               boolean includeStackTrace) {
                                                    RequestAttributes requestAttributes = new ServletRequestAttributes(request);
                                                    return this.errorAttributes.getErrorAttributes(requestAttributes,
                                                            includeStackTrace);
                                                }
                                            
                                                private HttpStatus getStatus(HttpServletRequest request) {
                                                    Integer statusCode = (Integer) request
                                                            .getAttribute("javax.servlet.error.status_code");
                                                    if (statusCode != null) {
                                                        try {
                                                            return HttpStatus.valueOf(statusCode);
                                                        }
                                                        catch (Exception ex) {
                                                        }
                                                    }
                                                    return HttpStatus.INTERNAL_SERVER_ERROR;
                                                }
                                            }
                                            

                                            以上类基于SpringsBasicErrorController类。

                                            您可以像这样在@Configuration 文件中实例化上述ErrorController

                                             @Autowired
                                             private ErrorAttributes errorAttributes;
                                            
                                             @Bean
                                             public AppErrorController appErrorController(){return new AppErrorController(errorAttributes);}
                                            

                                            您可以通过实现ErrorAttributes 来选择覆盖默认的ErrorAttributes。但在大多数情况下,DefaultErrorAttributes 就足够了。

                                            【讨论】:

                                            • 您指向BasicErrorController 404 类的链接。
                                            • BasicErrorController 的链接现已修复。
                                            【解决方案30】:

                                            我遇到了同样的问题,使用 gradle 并在添加以下依赖项时得到了解决-

                                            compile('org.springframework.boot:spring-boot-starter-data-jpa')
                                            compile('org.springframework.boot:spring-boot-starter-web')
                                            testCompile('org.springframework.boot:spring-boot-starter-test')
                                            compile('org.apache.tomcat.embed:tomcat-embed-jasper')
                                            

                                            之前我错过了导致同样错误的最后一个。

                                            【讨论】:

                                            • 我遇到了同样的问题,我在 pom.xml 中缺少 tomcat-embed-jasper 插件。而tomcat-embed-jasper对于渲染jsp很重要。
                                            • boraji.com/…,这导致发现tomcat-embed-jasper丢失了
                                            猜你喜欢
                                            • 1970-01-01
                                            • 1970-01-01
                                            • 2016-10-26
                                            • 2019-05-23
                                            • 2019-11-10
                                            • 2021-08-05
                                            • 2020-05-11
                                            • 1970-01-01
                                            相关资源
                                            最近更新 更多