2015-05-14 98 views
0

當我啓動控制檯時,我沒有遇到任何錯誤,但是當我嘗試訪問以下URL時:http://localhost:8080/projectShaun/home我得到以下錯誤:警告:在名爲DispatcherServlet的DispatcherServlet中沒有找到具有URI [/ projectShaun/home]的HTTP請求的映射

沒有映射在DispatcherServlet的發現HTTP請求與URI [/ projectShaun /]名爲「的DispatcherServlet

的DispatcherServlet-的servlet:

<?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-4.0.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> 

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

web.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" 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"> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>WEB-INF/applicationContext.xml</param-value> 
</context-param> 
    <servlet> 
     <servlet-name>DispatcherServlet</servlet-name> 
     <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>DispatcherServlet</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

的applicationContext:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task" 
    xsi:schemaLocation="http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/jee 
    http://www.springframework.org/schema/jee/spring-jee-3.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
    http://www.springframework.org/schema/task 
    http://www.springframework.org/schema/task/spring-task-3.2.xsd" > 

    <context:component-scan base-package="com.projectShaun.controller" /> 

    <mvc:annotation-driven /> 

    <tx:annotation-driven/> 
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
    <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
    <property name="url" value="jdbc:mysql://localhost:3306/projectshaun" /> 
    <property name="username" value="root" /> 
    <property name="password" value="" /> 
    </bean> 

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource"></property> 
    <property name="annotatedClasses"> 
      <list> 
       <value>com.projectShaun</value> 
      </list> 
     </property> 
    <property name="hibernateProperties"> 
     <props> 
     <prop 
     key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> 
     <prop key="hibernate.show_sql">true</prop> 
     </props> 
    </property> 
    </bean> 

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"> 
    </bean> 
</beans> 

的HomeController:

package com.projectShaun.controller; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.servlet.ModelAndView; 

import com.projectShaun.service.AccountService; 

@Controller 
public class HomeController { 

    @Autowired 
    AccountService accountService; 

    @RequestMapping(value = "/home") 
    public ModelAndView welcome() { 
     ModelAndView modelAndView = new ModelAndView("welcome"); 
     modelAndView.addObject("greeting", "Welcome to projectShaun!"); 
     return modelAndView; 
    } 
} 
+0

add' projectShaun'在web.xml –

+0

@RahulThachilath我添加這個後仍然得到404。 – Shaun

回答

-1

你有在WEB-INF/jsp的文件夾中的welcome.jsp文件?這可能是一個問題,你也可以檢查你的項目上下文根是否正確(右鍵單擊項目名稱 - >屬性 - > web項目設置 - >在上下文根目錄下應該是ProjectShaun)

+0

嗨 - 這可能是問題所在,但這看起來像評論/澄清而不是答案。爲了讓它成爲答案,你可以例如解釋該文件是什麼以及它會如何導致這個問題,等等 - 因爲這可能會被刪除。謝謝! – Rup

+0

@Rup我沒有足夠的評論聲望。更新我的回答 –

+0

@nileshvirkar yes我的welcome.jsp位於WEB-INF/jsp文件夾內。我檢查我的上下文根,它是projectShaun。 – Shaun

相關問題