邮递员在正确的路径上为 REST API 返回 404

Postman returning 404 for REST API on correct path

我创建了一个 Rest API。昨天我在邮递员上测试它并且它工作正常,今天它一直返回 404,文件路径没有改变所以不会错。我正在使用 tomcat,并且我的 xampp 已开启。 邮递员正在为我拥有的另一个应用程序返回正确的数据。

我要测试的路径是

http://localhost:8080/Assignment2C/breweries

我要测试的方法是

@RestController
@RequestMapping("/breweries")
public class Breweries_Controller {

    @Autowired
    Breweries_Service service;

    @GetMapping(produces = MediaTypes.HAL_JSON_VALUE)
    public Resources<Breweries> getAllBreweries() {
        List<Breweries> allBreweries = service.getAllBreweries();
        for (Breweries b : allBreweries) {
            int id = b.getResourceId();
            Link self = linkTo(this.getClass()).slash(id).withSelfRel();
            b.add(self);
            linkTo(methodOn(this.getClass()).getBrewerie(id));
        }
        Link link = linkTo(this.getClass()).withSelfRel();
        Resources<Breweries> result = new Resources<Breweries>(allBreweries, link);
        return result;

    }

我正在使用 JPA 连接到数据库。

项目结构是

配置文件是

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
    <context:component-scan base-package="Assignment2C" />



    <mvc:annotation-driven />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/views</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>  
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/sd4-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


</web-app>

也尝试提供获取映射的路径

   @GetMapping("/getAll")

你 url 应该看起来像

这个: http://localhost:8080/Assignment2C/breweries/getAll 要么 http://localhost:8080/2C/breweries/getAll

如果我将 base_package 设置为

<context:component-scan base-package="main" />

有效