2013-08-02 97 views
0

當我嘗試在tomcat服務器中部署應用程序時出現以下錯誤。請幫我解決這個問題。 localhost:8080/EnhancedRoyaltyTool /是我的主頁,它拋出錯誤。org.springframework.web.servlet.DispatcherServlet noHandlerFound基本彈簧示例

日誌消息:

Aug 02, 2013 8:33:37 PM org.apache.catalina.core.AprLifecycleListener init 
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_25\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Python27;C:\Python27\Scripts;. 
Aug 02, 2013 8:33:38 PM org.apache.tomcat.util.digester.SetPropertiesRule begin 
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:EnhancedRoyaltyTool' did not find a matching property. 
Aug 02, 2013 8:33:38 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["http-bio-8080"] 
Aug 02, 2013 8:33:38 PM org.apache.coyote.AbstractProtocol init 
INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 
Aug 02, 2013 8:33:38 PM org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 1007 ms 
Aug 02, 2013 8:33:38 PM org.apache.catalina.core.StandardService startInternal 
INFO: Starting service Catalina 
Aug 02, 2013 8:33:38 PM org.apache.catalina.core.StandardEngine startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42 
Aug 02, 2013 8:33:40 PM org.apache.catalina.core.ApplicationContext log 
INFO: No Spring WebApplicationInitializer types detected on classpath 
Aug 02, 2013 8:33:40 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'dispatcher' 
Aug 02, 2013 8:33:40 PM org.springframework.web.servlet.FrameworkServlet initServletBean 
INFO: FrameworkServlet 'dispatcher': initialization started 
Aug 02, 2013 8:33:40 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh 
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Aug 02 20:33:40 CDT 2013]; root of context hierarchy 
Aug 02, 2013 8:33:40 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] 
Aug 02, 2013 8:33:41 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 
INFO: Pre-instantiating singletons in org.s[email protected]196f4e87: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,viewResolver,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy 
Aug 02, 2013 8:33:42 PM org.springframework.web.servlet.FrameworkServlet initServletBean 
INFO: FrameworkServlet 'dispatcher': initialization completed in 1391 ms 
Aug 02, 2013 8:33:42 PM org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory C:\apache-tomcat-7.0.42\webapps\docs 
Aug 02, 2013 8:33:42 PM org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory C:\apache-tomcat-7.0.42\webapps\examples 
Aug 02, 2013 8:33:42 PM org.apache.catalina.core.ApplicationContext log 
INFO: ContextListener: contextInitialized() 
Aug 02, 2013 8:33:42 PM org.apache.catalina.core.ApplicationContext log 
INFO: SessionListener: contextInitialized() 
Aug 02, 2013 8:33:42 PM org.apache.catalina.core.ApplicationContext log 
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', '[email protected]') 
Aug 02, 2013 8:33:42 PM org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory C:\apache-tomcat-7.0.42\webapps\host-manager 
Aug 02, 2013 8:33:42 PM org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory C:\apache-tomcat-7.0.42\webapps\manager 
Aug 02, 2013 8:33:42 PM org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory C:\apache-tomcat-7.0.42\webapps\ROOT 
Aug 02, 2013 8:33:42 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-8080"] 
Aug 02, 2013 8:33:42 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
Aug 02, 2013 8:33:42 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 4363 ms 
Aug 02, 2013 8:33:43 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/EnhancedRoyaltyTool/] in DispatcherServlet with name 'dispatcher' 
My web.xml file 

<?xml version="1.0" encoding="UTF-8"?> 
    <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"> 

     <servlet> 
      <servlet-name>dispatcher</servlet-name> 
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
      <load-on-startup>1</load-on-startup> 
     </servlet> 

     <servlet-mapping> 
      <servlet-name>dispatcher</servlet-name> 
      <url-pattern>/</url-pattern> 
     </servlet-mapping> 
    </web-app> 

我的調度員servlet.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:p="http://www.springframework.org/schema/p" 
    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-3.1.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.1.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> 

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

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

我SearchController.java

package com.saas.royalties.controller; 

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

@Controller 
public class SearchController { 

    @RequestMapping(value="/") 
     public String printHelloWorld(ModelMap model) { 
      model.addAttribute("test", "test World!"); 
      System.out.println("test"); 
      return "hello"; 
     } 

} 

我pom.xml文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.saas.royalty</groupId> 
    <artifactId>EnhancedRoyaltyTool</artifactId> 
    <packaging>war</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>EnhancedRoyaltyTool Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
     <org.springframework.version>3.1.2.RELEASE</org.springframework.version> 
    </properties> 

    <dependencies> 
     <!-- Spring MVC depends on spring-core, spring-beans, spring-context, spring-web --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>${org.springframework.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.2</version> 
     </dependency> 

     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>EnhancedRoyaltyTool</finalName> 
    </build> 
</project> 

我的文件夾結構![文件夾結構] [1]

+0

你採取了什麼行動,給你那個錯誤信息?它是在啓動時,HTTP GET還是其他內容中顯示的? – chrylis

+0

我正在訪問默認主頁,即http:localhost:8080/EnhancedRoyaltyTool /。 –

回答

4

添加<mvc:default-servlet-handler/>我在調度員的servlet有固定的問題

+0

原因是Spring找不到你的控制器,把它添加到你的xml配置中: zengsn

1

這是URI的問題。你如何調用這個servlet?

+0

你能否更詳細地解釋我?我試圖訪問默認的http:localhost:8080/EnhancedRoyaltyTool/page –

2

你告訴servlet容器在servlet-mapping,你想在Spring調度附着/,你告訴春天的printHelloWorld方法應該用於辦理/相對於servlet的基礎(這只是/)請求。但是你試圖加載/EnhancedRoyaltyTool/,並且你還沒有告訴servlet容器或Spring在那裏附加任何東西。您可以將RequestMapping更改爲"/EnhancedRoyaltyTool/",將整個Spring servlet移動到servlet-mapping中的"/EnhancedRoyaltyTool/*",或者嘗試訪問​​。

+0

我對春天很陌生,但是,我假設我的pom創建了War EndhancedRoyaltyTool,並且默認情況下將其加載爲http:localhost: 8080/EnhancedRoyaltyTool /當我部署應用程序 –

+0

這取決於如何設置容器。事實上,你從Spring獲得一個錯誤(而不是容器中的錯誤)意味着容器將請求指向Spring,但Spring仍然在路徑中看到「EnhancedRoyaltyTool」的事實意味着請求是相對於servlet根目錄,必須是'/'。你從來沒有發佈完整的錯誤信息,但我正確地猜測你得到了404嗎? – chrylis

+0

是的,我收到了404錯誤。 –

0

首先,檢查調度的Servlet。如果你還檢查它,然後, 簡單的方法:你不需要通過構建路徑添加外部罐子。轉到項目工作區的文件夾,並直接複製下載的罐子並粘貼到:

WebContent>WEB-INF>lib>(here directly paste your jar files.) 

-> stop your application server (like tomcat); 
-> go to your IDE -> Select Project -> Clean Project builds 

之後,你去:運行你的項目。我希望它能起作用!

相關問題