在tomcat7上运行spring jpa项目时,找不到404错误

时间:2014-07-08 14:34:51

标签: spring ubuntu tomcat7

我正在尝试在ubuntu13.04上的tomcat7上部署spring jpa项目。我使用sh startup.sh启动了tomcat 我收到了消息" Tomcat Started"。 在此之前,我将我的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页面。

1 个答案:

答案 0 :(得分:0)

尝试以这种方式更改您的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>