我跟着sometutorials並在eclipse中創建了SpringMVC webapp。如何將Spring MVC部署到遠程Tomcat服務器上
我試圖在遠程運行的服務器上部署它,但我失敗了,不知道爲什麼?
這是我做的:在以下目錄:/fs/sda4/project/workspace/SpringMVC
我執行以下Maven命令:
/opt/apache-maven-2.2.1/bin/mvn -Dmaven.test.skip=true clean install
構建成功。
然後我複製下面的WAR文件
/fs/sda4/project/workspace/SpringMVC/target/SpringMVC.war
到服務器上,更確切地說在這裏:
/usr/pkg/tomcat/webapps/
現在我想到的是啓動Tomcat後,下面的網址應該帶我去打開頁面。
https://gaya.aac.com:8843/SpringMVC/
但它沒有,而是它給了我一個http狀態404,所請求的資源不可用。
這裏是Tomcat啓動的相關日誌:
INFO: Starting service Catalina
Jun 18, 2014 11:46:27 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.53
Jun 18, 2014 11:46:27 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /usr/pkg/tomcat-rusznak/webapps/SpringMVC.war
[[email protected]] info AspectJ Weaver Version 1.7.3 built on Thursday Jun 13, 2013 at 19:41:31 GMT
[[email protected]] info register classloader [email protected]
[[email protected]] info no configuration found. Disabling weaver for class loader [email protected]
Jun 18, 2014 11:46:29 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Jun 18, 2014 11:46:29 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Jun 18, 2014 11:46:29 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Wed Jun 18 11:46:29 CEST 2014]; root of context hierarchy
Jun 18, 2014 11:46:29 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
Jun 18, 2014 11:46:29 AM org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider registerDefaultFilters
INFO: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
Jun 18, 2014 11:46:29 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]1b3c0cef: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
Jun 18, 2014 11:46:29 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 455 ms
Jun 18, 2014 11:46:29 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'mvc-dispatcher'
Jun 18, 2014 11:46:29 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'mvc-dispatcher': initialization started
Jun 18, 2014 11:46:29 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Wed Jun 18 11:46:29 CEST 2014]; parent: Root WebApplicationContext
Jun 18, 2014 11:46:29 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
Jun 18, 2014 11:46:29 AM org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider registerDefaultFilters
INFO: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
Jun 18, 2014 11:46:29 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]463e0db0: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; parent: org.s[email protected]1b3c0cef
Jun 18, 2014 11:46:30 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/welcome] onto handler 'helloController'
Jun 18, 2014 11:46:30 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/welcome.*] onto handler 'helloController'
Jun 18, 2014 11:46:30 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/welcome/] onto handler 'helloController'
Jun 18, 2014 11:46:30 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'mvc-dispatcher': initialization completed in 343 ms
Jun 18, 2014 11:46:30 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8843"]
Jun 18, 2014 11:46:30 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2341 ms
Jun 18, 2014 11:49:16 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/] in DispatcherServlet with name 'mvc-dispatcher'
Jun 18, 2014 11:49:22 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/WEB-INF/pages/hello.jsp] in DispatcherServlet with name 'mvc-dispatcher'
Jun 18, 2014 11:50:00 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/] in DispatcherServlet with name 'mvc-dispatcher'
Jun 18, 2014 11:50:06 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/WEB-INF/pages/hello.jsp] in DispatcherServlet with name 'mvc-dispatcher'
Jun 18, 2014 11:53:20 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/WEB-INF/pages/hello.jsp] in DispatcherServlet with name 'mvc-dispatcher'
Jun 18, 2014 11:53:58 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/] in DispatcherServlet with name 'mvc-dispatcher'
Jun 18, 2014 12:31:27 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC/WEB-INF/pages/hello.jsp] in DispatcherServlet with name 'mvc-dispatche
這裏web.xml中
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Web MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
,這裏是MVC-dispatcher.servlet
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.mkyong.common.controller" />
<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>
您shouldpost你的web.xml和XYZ-servlet.xml中。 – Stefan
請顯示應該處理'打開頁面'的控制器。 –