【问题标题】:Getting 404 not found error when running spring jpa project on tomcat7在tomcat7上运行spring jpa项目时出现404未找到错误
【发布时间】:2014-07-08 14:34:50
【问题描述】:

我正在尝试在 ubuntu13.04 上的 tomcat7 上部署 spring jpa 项目。我使用sh startup.sh启动了tomcat 我收到消息“Tomcat 已启动”。 在此之前,我将我的 ROOT.war 复制到 /usr/share/tomcat7/webapps 并获得了对该文件夹的完全权限。我可以看到它的结构正确。

下面是我的 web.xml

    <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_2_5.xsd" version="2.5">
  <display-name>Test App</display-name> 
 <servlet>
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
 <init-param>
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> 
     </init-param>
     <load-on-startup>1</load-on-startup> 
 </servlet>
 <context-param>
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/spring-context.xml</param-value> 
 </context-param>
 <servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
 </servlet-mapping>
 <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener class> 
 </listener>
 </web-app>

下面的代码是我的控制器的一部分:

@Controller
@RequestMapping("/issue")
public class IssueController {

    @RequestMapping(value="/{userId}", method = RequestMethod.GET)
     function to handle above request
}

下面是我的 mvc-dispatcher-servlet.xml

<context:component-scan base-package="com.test.hello" />
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"   />
       <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
                    <property name="favorPathExtension" value="true" />
                    <property name="favorParameter" value="true" />
                    <property name="mediaTypes" >
                        <value>
                            json=application/json
                            xml=application/xml
                        </value>
                    </property>
      </bean>

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

但是现在当我运行 http://localhost:8080/issue/1 时,我得到 404 page not found。

【问题讨论】:

  • 你的 web.xml 中有 ContextLoaderListener 吗?
  • 你可以分享你的 web.xml 完整吗?
  • 作为测试,请尝试应用这个小改动 (value="/user/{userId}", method = RequestMethod.GET)。让我知道它的行为(我想我知道问题所在)。还要确保调用 /issue/user/1 来访问该方法。
  • @Aeseir:我会测试它并让你知道结果。现在做不到。但是你能给我一些提示吗?我很想知道这个问题。
  • @Skizzo:发布完整的 web.xml

标签: spring ubuntu tomcat7


【解决方案1】:

尝试以这种方式更改您的 web.xml:

    <web-app>
     <servlet>
         <servlet-name>mvc-dispatcher</servlet-name> 
         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
            <init-param>
                <param-name>contextConfigLocation</param-name> 
                <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> 
            </init-param>
         <load-on-startup>1</load-on-startup> 
     </servlet>


     <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name> 
        <url-pattern>/*</url-pattern> 
     </servlet-mapping>
     <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener class> 
     </listener>
    </web-app>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多