【问题标题】:Spring Boot with Rest API 404带有 Rest API 404 的 Spring Boot
【发布时间】:2019-08-02 04:44:09
【问题描述】:

API 在没有 spring-boot 的情况下工作,但在 spring-boot 下就不行了。

@RequestMapping("/operationsOnEmployee")

    @RestController
    public class OperationsOnEmployee {

        @Autowired
        EmployeeFacade employeeFacade;

        @GetMapping(produces = "application/json")
        public List<Employee> getEmployee() {
            System.out.println("hello");
            return employeeFacade.getAllEmployee();
        }

application.properties

server.port:8080
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect
spring.datasource.url=jdbc:mysql://localhost:3306/company
spring.datasource.username=root
spring.datasource.password=root

    "timestamp": "2019-08-01T11:34:07.631+0000",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/operationsOnEmployee"

【问题讨论】:

  • 发布你的包结构和扫描所有包的应用程序类
  • 我没有将我的主文件和控制器放在同一个包中。现在它工作正常。
  • 将文件放入同一个包后,现在可以正常工作了吗?

标签: spring rest spring-boot


【解决方案1】:

使用

@GetMapping(value= "/operation", produces = "application/json")

打电话

GET:   localhost:8080/operationsOnEmployee/operation

另外,请确保您没有application.properties 中定义任何路径

server.servlet.context-path= #some path

【讨论】:

  • @mayursinghal,您是否按照上次编辑添加了,您是否有任何server.servlet.context-path。同时使用您最近的更改更新问题
  • 您好 @mayursinghal 将 path 更改为 value 更新后的答案
  • 具有值的路径。在哪里改变
  • @mayursinghal 使用@GetMapping(value= "/operation", produces = "application/json")
  • @mayursinghal 现在一切都很好,您可以添加更多细节或分享 git 链接
【解决方案2】:

尝试在 @GetMapping 中提供映射 URL 以将您的方法映射为:

@GetMapping("/mappingURL")

获取网址:localhost:8080/operationsOnEmployee/mappingURL

如果不清理项目并重新运行

【讨论】:

  • 在上面的答案@Patel 中提到确切的程序是什么。尝试给出好的答案。
猜你喜欢
  • 1970-01-01
  • 2018-04-07
  • 2018-12-10
  • 2020-04-12
  • 2018-04-18
  • 2020-08-04
  • 2019-07-18
  • 2016-11-28
  • 2021-05-14
相关资源
最近更新 更多