2016-11-04 117 views
0

我是新的春天和404的問題是我現在崩潰,我複製一些春天MVC演示,並總是得到404錯誤,當我嘗試訪問該網站。404錯誤與SpringMVC(Intellij)

這裏是我的項目:

結構:

enter image description here

web.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 
    <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/spring_mvc_demo.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> 

spring_mvc_demo.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

<context:component-scan base-package="spring_demo.controller"></context:component-scan> 
<mvc:annotation-driven/> 

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

的LoginController:

package spring_demo.controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 

@Controller 
public class LoginController { 
    @RequestMapping(value = "/") 
    public String showPage(){ 
     System.out.println("show page"); 
     return "test"; 
    } 
} 

好像我啓動Tomcat後,用SpringMVC沒有得到控制。但我找不到問題。

另外我有web.xml的問題,添加這個時總會出錯。

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

錯誤:

SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file 
SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors 
+2

你可以通過你的容器日誌的例外跟蹤 – kuhajeyan

+0

對不起,但我找不到有關異常的任何容器日誌文件。 Tomcat仍然沒有任何異常運行,它表明工件部署期間出現錯誤,我無法訪問tomcat服務器。 –

回答

0

在pom.xml中描述到Tomcat的lib文件夾手動複製所需的所有jar文件。 這對我有用。