Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 爪哇8及;Spring MVC:错误“;“404未找到”;删除常量接口时已解决。有什么问题?_Java_Spring_Spring Mvc - Fatal编程技术网

Java 爪哇8及;Spring MVC:错误“;“404未找到”;删除常量接口时已解决。有什么问题?

Java 爪哇8及;Spring MVC:错误“;“404未找到”;删除常量接口时已解决。有什么问题?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个包含GET方法的类。当我试图与邮递员联系时,我得到一个404未找到错误但是,如果我删除“implements SubscriptionConstants”并使用完全相同的请求调用它,则一切正常(状态代码200)。 下面是我得到404错误的类: import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.

我有一个包含GET方法的类。当我试图与邮递员联系时,我得到一个404未找到错误但是,如果我删除“implements SubscriptionConstants”并使用完全相同的请求调用它,则一切正常(状态代码200)。

下面是我得到404错误的类:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; 
// other imports

@Controller
@Measured(canStartRootStack = true)
public class AlertsResource extends AbstractResource implements SubscriptionConstants {


    @Autowired
    private SubscriptionSubscriberService subscriptionSubscriberService;

    @RequestMapping(value = "/alerts/{triggerid}/subscribers", method = RequestMethod.GET,
            produces = APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public List<SubscriptionSubscriber> loadSubscribers(@PathVariable final String triggerid) {
        return subscriptionSubscriberService.getSubscribers(triggerid);
    }
 
   // other methods...

    }
SubscriptionConstants是一个接口,但它只包含以下常量:

String  USER                            = "user";
String  LOGIN                           = "login";
以下是mvc-servlet.xml文件:

<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" xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        ">

    <!-- Sub Context used for Rest services -->

    <aop:aspectj-autoproxy />

    <context:component-scan base-package="com.mycompany.myapp.webapp.resource" />
    <context:property-placeholder/>
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="false">
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="objectMapper" ref="jsonObjectMapper"/>
            </bean>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
        </mvc:message-converters>
    </mvc:annotation-driven>

</beans>
<!-- Spring MVC -->
<servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:com/mycompany/myapp/webapp/mvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>mvc</servlet-name>
    <url-pattern>/resource/*</url-pattern>
</servlet-mapping>
但我仍然不知道为什么“实现SubscriptionConstants”会导致404错误


当仍然存在“implements SubscriptionConstants”时,我在启动Tomcat服务器时检查了日志,我在日志中没有发现任何错误,并且带有关键字“controller”或“AlertsResource”或“SubscriptionConstants”的内容都不是同一个包下的文件。如果可能的话,你能分享项目结构的截图吗。一个原因可能是其中一个文件位于未被扫描的包中。可能是因为不是主应用程序包的子应用程序。您可以发布控制器的映射方式吗?。是的,两个文件都在同一个包中。请共享失败的类中控制器注释的导入语句。@JamesJithin我在我的帖子中添加了导入
<!-- Spring MVC -->
<servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:com/mycompany/myapp/webapp/mvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>mvc</servlet-name>
    <url-pattern>/resource/*</url-pattern>
</servlet-mapping>
import static com.mycompany.myapp.service.alert.subscription.constants.SubscriptionConstants.USER;