java - 出现意外错误(类型=未找到,状态=404)。- 春季Java
问题描述
我在 github 中有这个服务https://github.com/felloz/personsService应用程序编译没有错误但是当我试图访问路由http://localhost:8080/demo/persons我得到这个错误:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon May 11 14:55:30 VET 2020
There was an unexpected error (type=Not Found, status=404).
No message available
编译消息:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.7.RELEASE)
2020-05-11 15:05:55.576 INFO 10476 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on lserrano-PC with PID 10476 (C:\JAVA\Eclipse Projects\demo\target\classes started by lserrano in C:\JAVA\Eclipse Projects\demo)
2020-05-11 15:05:55.592 INFO 10476 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-05-11 15:05:58.173 INFO 10476 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-11 15:05:58.198 INFO 10476 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-11 15:05:58.198 INFO 10476 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.34]
2020-05-11 15:05:58.386 INFO 10476 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-11 15:05:58.387 INFO 10476 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2685 ms
2020-05-11 15:05:58.857 INFO 10476 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-05-11 15:05:59.362 INFO 10476 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-11 15:05:59.377 INFO 10476 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 4.578 seconds (JVM running for 5.433)
2020-05-11 15:06:14.712 INFO 10476 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-05-11 15:06:14.712 INFO 10476 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-05-11 15:06:14.727 INFO 10476 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 15 ms
您可以检查 github 存储库中的代码,我是 Sprong 的新手,我将不胜感激,我使用 NetBeans 作为 IDE。
添加 server.servlet.context-path=/demo 后
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.7.RELEASE)
2020-05-11 17:26:54.336 INFO 9144 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on lserrano-PC with PID 9144 (C:\JAVA\Eclipse Projects\demo\target\classes started by lserrano in C:\JAVA\Eclipse Projects\demo)
2020-05-11 17:26:54.336 INFO 9144 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-05-11 17:26:56.926 INFO 9144 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-11 17:26:56.957 INFO 9144 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-11 17:26:56.957 INFO 9144 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.34]
2020-05-11 17:26:57.160 INFO 9144 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/demo] : Initializing Spring embedded WebApplicationContext
2020-05-11 17:26:57.160 INFO 9144 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2715 ms
2020-05-11 17:26:57.612 INFO 9144 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-05-11 17:26:58.111 INFO 9144 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/demo'
2020-05-11 17:26:58.111 INFO 9144 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 4.591 seconds (JVM running for 5.464)
2020-05-11 17:27:14.361 INFO 9144 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/demo] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-05-11 17:27:14.362 INFO 9144 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-05-11 17:27:14.379 INFO 9144 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 17 ms
解决方案
你有@RequestMapping({"/persons"})
你的控制器,所以试试这个链接http://localhost:8080/persons
没有demo
推荐阅读
- graphics - 如何正确应用透视投影矩阵
- android - JetpackCompose 布局中的自定义类
- oracle - 将变量与查询中的值进行比较
- wordpress - 如何删除 Wordpress 控制台警告?
- visual-studio - 在 git 操作中运行用于构建 VS 项目(Linux config/wsl)的 powershell 脚本
- java - 在java中为实体创建角色?
- ios - 如果孩子使用环境对象,如何停止刷新视图
- powershell - 在 PowerShell 中从 2 个变量创建递增变量
- html - Python Selenium 从内联的锚点获取链接文本
- algorithm - 为数组中的每个元素查找 k 个最接近的整数