spring - HTTP 状态 404 - 在 Spring Boot 中调用 url 时未找到
问题描述
在简单创建的 Spring Boot 应用程序的浏览器上调用 URL 时,我得到 HTTP 状态 404。下面是代码。我的代码中没有错误或问题。我只是从互联网上复制我的代码。
主要的 spring boot 应用程序类
package com.springboot.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class SampleBootAppApplication {
public static void main(String[] args) {
SpringApplication.run(SampleBootAppApplication.class, args);
}
}
下面是控制器类
控制器类
package com.springboot.app.controller;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class AppController {
@GetMapping("/test")
@ResponseBody
public String getName()
{
return "adil abdullah";
}
}
项目结构:
解决方案
访问 URL 错误:http://localhost:8080/test 它应该有上下文路径,它将在 application.properties 文件中,如 server.servlet.context.path = /samplebootapp 访问 URL:http://localhost: 8080/samplebootapp/测试
推荐阅读
- c++ - 如何定义类型取决于指针大小是否等于特定值的变量
- c# - AzureAd 身份验证始终使用服务器的本地 IP 地址作为 redirect_url
- python - 在 Python 中拆分后包含前两个字符
- drools - 流口水:{} 大括号和结果中的条件 - 大括号会有所不同,它们在 Java 中没有
- c# - 程序关闭后保持组合框选定的值 WPF C#
- database - PostgreSQL 错误:必须是公共架构的所有者
- c# - 使用 Azure Devops API,如何从 .xlsx 文件创建项目?
- reactjs - React 测试库 + 路由器
- python - groupby 合并期间 pd.IntervalIndex.from_arrays 出错
- javascript - 如果内部循环在 React 中没有按预期工作