如何将Spring MVC部署到远程Tomcat服务器

时间:2014-06-18 10:31:00

标签: eclipse maven tomcat spring-mvc deployment

我关注some tutorials并在eclipse中创建了一个SpringMVC webapp。

我尝试在远程运行的服务器下部署它,但我失败了,不知道为什么?

以下是我所做的:在以下目录中:/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之后,以下URL会带我到开始页面。

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
    [WebappClassLoader@4c01acb7] info AspectJ Weaver Version 1.7.3 built on Thursday Jun 13, 2013 at 19:41:31 GMT
    [WebappClassLoader@4c01acb7] info register classloader org.apache.catalina.loader.WebappClassLoader@4c01acb7
    [WebappClassLoader@4c01acb7] info no configuration found. Disabling weaver for class loader org.apache.catalina.loader.WebappClassLoader@4c01acb7
    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.springframework.beans.factory.support.DefaultListableBeanFactory@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.springframework.beans.factory.support.DefaultListableBeanFactory@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.springframework.beans.factory.support.DefaultListableBeanFactory@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>

1 个答案:

答案 0 :(得分:0)

相关问题