【问题标题】:Spring REST: 404 on simple REST RequestSpring REST:简单 REST 请求上的 404
【发布时间】:2018-05-26 12:22:59
【问题描述】:

我正在拼命尝试让我的 Rest 控制器工作。这是一个简单的 Rest 控制器昨天已经工作,但在今天的构建之后就不行了。我没有更改任何一行,只是重新构建了项目。

控制器:

@RestController
@RequestMapping("/ws")
  public class UserController {

  @Autowired
  private UserRepository userRepo;

  @RequestMapping("/hello")
  public String hello() {return "Hello";}  .....

在:

http://localhost:8080/ws/hello

错误信息:

出现意外错误(类型=未找到,状态=404)。 没有可用的消息

Eclipse 快把我逼疯了。每次我清理构建时,我都会冒我的代码不再工作的风险。

POM.xml 依赖:

<dependencies>      
        <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.3.0</version>
        </dependency>

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


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

        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>   
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

    </dependencies>

【问题讨论】:

  • 项目部署正确?在构建之前尝试刷新项目。
  • 不。还是404
  • 有没有在 applicationcontext.xml 或 yml 文件中配置“server.contextPath”?此外,如果您启用 spring 包的调试日志,它应该会告诉您在代码中发现了哪些 API 端点以及相应的完全限定方法名称。这将帮助您进一步调试。
  • 配置 contextPath 没有改变任何东西。正如所说的代码昨天已经工作了

标签: spring rest spring-data-jpa


【解决方案1】:

通过将项目转移到 STS 的新副本使其工作。不知道是什么损坏了 eclipse。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-21
    • 2020-01-30
    • 1970-01-01
    • 2021-09-19
    • 2023-03-09
    • 1970-01-01
    • 2014-05-25
    • 2017-04-20
    相关资源
    最近更新 更多