白标错误页面。此应用未配置错误视图,因此您正在看到此页面作为回退。

huangapple go评论91阅读模式
英文:

Whitelabel Error Page This application has no configured error view, so you are seeing this as a fallback

问题

我开始构建一个Spring Boot应用程序,但是我遇到了这种错误:“白标错误页面 - 此应用程序没有配置错误视图,因此您正在看到此回退。”<br>
我是从https://start.spring.io/创建的项目。

DemoApplication.java

  1. package com.example.demo;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.web.bind.annotation.GetMapping;
  5. import org.springframework.web.bind.annotation.RequestParam;
  6. @SpringBootApplication
  7. public class DemoApplication {
  8. public static void main(String[] args) {
  9. SpringApplication.run(DemoApplication.class, args);
  10. }
  11. @GetMapping("/hello")
  12. public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
  13. return String.format("Hello %s!", name);
  14. }
  15. }

pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.3.3.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example.demo</groupId>
  12. <artifactId>demo</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>demo</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-webflux</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-test</artifactId>
  27. <scope>test</scope>
  28. <exclusions>
  29. <exclusion>
  30. <groupId>org.junit.vintage</groupId>
  31. <artifactId>junit-vintage-engine</artifactId>
  32. </exclusion>
  33. </exclusions>
  34. </dependency>
  35. <dependency>
  36. <groupId>io.projectreactor</groupId>
  37. <artifactId>reactor-test</artifactId>
  38. <scope>test</scope>
  39. </dependency>
  40. </dependencies>
  41. <build>
  42. <plugins>
  43. <plugin>
  44. <groupId>org.springframework.boot</groupId>
  45. <artifactId>spring-boot-maven-plugin</artifactId>
  46. </plugin>
  47. </plugins>
  48. </build>
  49. </project>

项目结构:白标错误页面。此应用未配置错误视图,因此您正在看到此页面作为回退。

我不理解问题出在哪里。

英文:

I am started building a spring boot application but i am getting this type of error "Whitelabel Error Page - This application has no configured error view, so you are seeing this as a fallback." <br>
I created the project from https://start.spring.io/.

白标错误页面。此应用未配置错误视图,因此您正在看到此页面作为回退。

  1. . ____ _ __ _ _
  2. /\\ / ___&#39;_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | &#39;_ | &#39;_| | &#39;_ \/ _` | \ \ \ \
  4. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. &#39; |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v2.3.3.RELEASE)
  8. 2020-09-09 16:12:00.389 INFO 19440 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on ***** with PID 19440 (C:\Users\m.petraglia\Desktop\demo\target\classes started by m.petraglia in C:\Users\m.petraglia\Desktop\demo)
  9. 2020-09-09 16:12:00.391 INFO 19440 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
  10. 2020-09-09 16:12:01.024 DEBUG 19440 --- [ main] o.s.w.r.handler.SimpleUrlHandlerMapping : Patterns [/webjars/**, /**] in &#39;resourceHandlerMapping&#39;
  11. 2020-09-09 16:12:01.118 DEBUG 19440 --- [ main] o.s.w.r.r.m.a.ControllerMethodResolver : ControllerAdvice beans: none
  12. 2020-09-09 16:12:01.138 DEBUG 19440 --- [ main] o.s.w.s.adapter.HttpWebHandlerAdapter : enableLoggingRequestDetails=&#39;false&#39;: form data and headers will be masked to prevent unsafe logging of potentially sensitive data
  13. 2020-09-09 16:12:01.961 INFO 19440 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
  14. 2020-09-09 16:12:01.967 INFO 19440 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.837 seconds (JVM running for 2.132)
  15. 2020-09-09 16:12:07.977 DEBUG 19440 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [22183960-1] HTTP GET &quot;/hello&quot;
  16. 2020-09-09 16:12:07.998 DEBUG 19440 --- [ctor-http-nio-2] o.s.w.r.handler.SimpleUrlHandlerMapping : [22183960-1] Mapped to ResourceWebHandler [&quot;classpath:/META-INF/resources/&quot;, &quot;classpath:/resources/&quot;, &quot;classpath:/static/&quot;, &quot;classpath:/public/&quot;]
  17. 2020-09-09 16:12:08.000 DEBUG 19440 --- [ctor-http-nio-2] o.s.w.r.resource.ResourceWebHandler : [22183960-1] Resource not found
  18. 2020-09-09 16:12:08.025 DEBUG 19440 --- [ctor-http-nio-2] org.springframework.web.HttpLogging : [22183960-1] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /hello
  19. 2020-09-09 16:12:08.031 DEBUG 19440 --- [ctor-http-nio-2] org.springframework.web.HttpLogging : [22183960-1] Writing &quot;&lt;html&gt;&lt;body&gt;&lt;h1&gt;Whitelabel Error Page&lt;/h1&gt;&lt;p&gt;This application has no configured error view, so you (truncated)...
  20. 2020-09-09 16:12:08.042 DEBUG 19440 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [22183960-1] Completed 404 NOT_FOUND

DemoApplication.java

  1. package com.example.demo;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.web.bind.annotation.GetMapping;
  5. import org.springframework.web.bind.annotation.RequestParam;
  6. @SpringBootApplication
  7. public class DemoApplication {
  8. public static void main(String[] args) {
  9. SpringApplication.run(DemoApplication.class, args);
  10. }
  11. @GetMapping(&quot;/hello&quot;)
  12. public String hello(@RequestParam(value = &quot;name&quot;, defaultValue = &quot;World&quot;) String name) {
  13. return String.format(&quot;Hello %s!&quot;, name);
  14. }
  15. }

pom.xml

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  2. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  3. xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  4. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  5. &lt;parent&gt;
  6. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  7. &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
  8. &lt;version&gt;2.3.3.RELEASE&lt;/version&gt;
  9. &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  10. &lt;/parent&gt;
  11. &lt;groupId&gt;com.example.demo&lt;/groupId&gt;
  12. &lt;artifactId&gt;demo&lt;/artifactId&gt;
  13. &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  14. &lt;name&gt;demo&lt;/name&gt;
  15. &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  16. &lt;properties&gt;
  17. &lt;java.version&gt;1.8&lt;/java.version&gt;
  18. &lt;/properties&gt;
  19. &lt;dependencies&gt;
  20. &lt;dependency&gt;
  21. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  22. &lt;artifactId&gt;spring-boot-starter-webflux&lt;/artifactId&gt;
  23. &lt;/dependency&gt;
  24. &lt;dependency&gt;
  25. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  26. &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
  27. &lt;scope&gt;test&lt;/scope&gt;
  28. &lt;exclusions&gt;
  29. &lt;exclusion&gt;
  30. &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
  31. &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
  32. &lt;/exclusion&gt;
  33. &lt;/exclusions&gt;
  34. &lt;/dependency&gt;
  35. &lt;dependency&gt;
  36. &lt;groupId&gt;io.projectreactor&lt;/groupId&gt;
  37. &lt;artifactId&gt;reactor-test&lt;/artifactId&gt;
  38. &lt;scope&gt;test&lt;/scope&gt;
  39. &lt;/dependency&gt;
  40. &lt;/dependencies&gt;
  41. &lt;build&gt;
  42. &lt;plugins&gt;
  43. &lt;plugin&gt;
  44. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  45. &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  46. &lt;/plugin&gt;
  47. &lt;/plugins&gt;
  48. &lt;/build&gt;
  49. &lt;/project&gt;

Project structure:

白标错误页面。此应用未配置错误视图,因此您正在看到此页面作为回退。

I don't understand what is the problem.

答案1

得分: 2

尝试在类上添加 @RestController 注解

英文:

Try adding @RestController annotation to the class

答案2

得分: 0

或许你应该使用 HTML 文件在浏览器中运行它,这是我的意见。如果你使用 Thymeleaf,也要包含相关的依赖。

英文:

maybe you should use html file to run it in browser in my opinion,and also if you use thymeleaf include the dependencies as well

huangapple
  • 本文由 发表于 2020年9月9日 22:28:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63813805.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定