2012-09-13 46 views
1

我有一個運行就好在Eclipse中,但也有小的Java/Spring MVC的REST/Maven的應用程序,當我運行在提示符下輸入以下命令:的Java的webapp運行正常在Eclipse中,但不是在Tomcat的

MVN乾淨的tomcat6:運行

我的問題是,當我做:

MVN清潔套裝

並將生成的war文件推送到獨立Tomcat實例中的「webapps」文件夾,該服務不再工作。

獨立的Tomcat啓動正常,日誌中沒有錯誤。有趣的是,當我在Eclipse中運行應用程序或通過mvn命令時,獨立實例在端口8989與8080上進行偵聽。

一旦應用程序在獨立的Tomcat中運行,如果我試圖打開我的服務w/RESTClient,我會返回404。我的自定義404實際上,不是通用的。

此外靜態內容,就像我的index.html出現就好了。

這裏是我的web.xml文件:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<web-app 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>Skunk User Interface</display-name> 

    <context-param> 
    <param-name>log4jConfigLocation</param-name> 
    <param-value>file:///${APPS_CONFIG}/log4j.xml</param-value> 
    </context-param> 

    <listener> 
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
    </listener> 

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

    <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/skunk-servlet.xml 
    </param-value> 
    </context-param> 

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

    <servlet-mapping> 
    <servlet-name>skunk</servlet-name> 
    <url-pattern>/skunk/*</url-pattern> 
    </servlet-mapping> 

    <!-- Healthcheck mapping --> 
    <servlet-mapping> 
    <servlet-name>skunk</servlet-name> 
    <url-pattern>/health/*</url-pattern> 
    </servlet-mapping> 

    <error-page> 
    <error-code>404</error-code> 
    <location>/WEB-INF/404.htm</location> 
    </error-page> 
</web-app> 

以及臭鼬-servlet.xml中:

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xmlns:c="http://www.springframework.org/schema/c" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:p="http://www.springframework.org/schema/p" 
     xmlns:cache="http://www.springframework.org/schema/cache" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-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/tx 
     http://www.springframework.org/schema/tx/spring-tx-3.1.xsd 
     http://www.springframework.org/schema/aop 
     http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
     http://www.springframework.org/schema/cache 
     http://www.springframework.org/schema/cache/spring-cache-3.1.xsd"> 

    <tx:annotation-driven/> 

    <!-- Load configuration settings --> 
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="ignoreUnresolvablePlaceholders" value="true" /> 
    </bean> 

    <bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer"> 
     <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> 
     <property name="searchContextAttributes" value="true" /> 
     <property name="contextOverride" value="true" /> 
     <property name="ignoreResourceNotFound" value="true" /> 
     <property name="locations"> 
     <list> 
      <value>classpath:config/application.properties</value> 
      <value>file:///${APPS_CONFIG}/application.properties</value> 
     </list> 
     </property> 
    </bean> 

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="${jdbc.driverClassName}" /> 
    <property name="url" value="${jdbc.url}" /> 
    <property name="username" value="${jdbc.username}" /> 
    <property name="password" value="${jdbc.password}" /> 
    </bean> 

    <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" 
    c:dataSource-ref="dataSource" /> 

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource"> 
     <ref bean="dataSource"/> 
    </property> 
    <property name="hibernateProperties"> 
     <props> 
     <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
     </props> 
    </property> 
    </bean> 

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

    <!-- Auto scan the components --> 
    <context:component-scan base-package="com.skunk.myapp" /> 
    <mvc:annotation-driven/> 

    <cache:annotation-driven /> 

    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> 
     <property name="cacheManager" ref="ehcache"/> 
    </bean> 
    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> 
    <property name="configLocation" value="classpath:/ehcache.xml"/> 
    </bean> 

    <aop:aspectj-autoproxy proxy-target-class="true" /> 

</beans> 

是否有該配置任何可以解釋爲什麼任何請求調度的servlet返回404而不是路由到控制器?

感謝


UPDATE:

從Tomcat獨立添加日誌輸出。 。

卡塔利娜[日期] .LOG:

Sep 13, 2012 1:47:28 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.6.0_31\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;. 
Sep 13, 2012 1:47:28 PM org.apache.coyote.http11.Http11Protocol init 
INFO: Initializing Coyote HTTP/1.1 on http-8080 
Sep 13, 2012 1:47:28 PM org.apache.catalina.startup.Catalina load 
INFO: Initialization processed in 673 ms 
Sep 13, 2012 1:47:28 PM org.apache.catalina.core.StandardService start 
INFO: Starting service Catalina 
Sep 13, 2012 1:47:28 PM org.apache.catalina.core.StandardEngine start 
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32 
Sep 13, 2012 1:47:28 PM org.apache.catalina.startup.HostConfig deployDescriptor 
INFO: Deploying configuration descriptor host-manager.xml 
Sep 13, 2012 1:47:29 PM org.apache.catalina.startup.HostConfig deployDescriptor 
INFO: Deploying configuration descriptor manager.xml 
Sep 13, 2012 1:47:29 PM org.apache.catalina.startup.HostConfig deployWAR 
INFO: Deploying web application archive skunk.war 
Sep 13, 2012 1:47:44 PM org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory docs 
Sep 13, 2012 1:47:44 PM org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory examples 
Sep 13, 2012 1:47:44 PM org.apache.catalina.startup.HostConfig deployDirectory 
INFO: Deploying web application directory ROOT 
Sep 13, 2012 1:47:44 PM org.apache.coyote.http11.Http11Protocol start 
INFO: Starting Coyote HTTP/1.1 on http-8080 
Sep 13, 2012 1:47:44 PM org.apache.jk.common.ChannelSocket init 
INFO: JK: ajp13 listening on /0.0.0.0:8009 
Sep 13, 2012 1:47:44 PM org.apache.jk.server.JkMain start 
INFO: Jk running ID=0 time=0/19 config=null 
Sep 13, 2012 1:47:44 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 16106 ms 

本地主機[日期] .LOG:

Sep 13, 2012 1:47:39 PM org.apache.catalina.core.ApplicationContext log 
INFO: Set web app root system property: 'webapp.root' = [C:\Users\my.user\Tomcat\webapps\skunk\] 
Sep 13, 2012 1:47:39 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing log4j from [file:///${APPS_CONFIG}/log4j.xml] 
Sep 13, 2012 1:47:39 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 
Sep 13, 2012 1:47:43 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'skunk' 
Sep 13, 2012 1:47:44 PM org.apache.catalina.core.ApplicationContext log 
INFO: ContextListener: contextInitialized() 
Sep 13, 2012 1:47:44 PM org.apache.catalina.core.ApplicationContext log 
INFO: SessionListener: contextInitialized() 

回答

2

如果你只是yourproject.war複製到Tomcat的webapps文件夾,並讓默認部署在踢(將yourproject.war擴展爲名爲yourproject的目錄),那麼您應該知道默認的Tomcat邏輯是使您的應用在/yourproject的上下文路徑(讀取:URL)下可用。

如果您希望應用程序在根上下文(/)下可用,您應該適當地配置Tomcat。

+0

這很好,我實際上使用http:// localhost:8989/skunk/myService進行測試。所以我會認爲這應該是正確的? – Lancelot

+0

什麼是戰爭文件名? Tomcat配置運行的端口是什麼?你看過*所有的tomcat日誌文件 - 他們在部署戰爭和啓動時說什麼? –

+0

戰爭文件是skunk.war,順便說一句,我沒有觸及任何配置文件,並在窺視後發現8989端口被定義在那裏。我把它改回到8080的初學者,它沒有解決任何問題,但它更一致。 – Lancelot

1

所以這是你的組合。

應用 - 環境狀態
Eclipse的>工作
Eclipse的嵌入式TOMCAT - >工作
獨立TOMCAT - >不工作

看日食Tomcat的偏好,它可能添加的類路徑和庫路徑,其會讓Tomcat識別。面臨過去類似的問題。

此外,您的靜態內容工作正常。這意味着一些重要的jar運行在eclipse classpath中,這在獨立Tomcat中是不可見的。

乾杯

+0

其實我不確定這是否有所作爲,但我沒有嵌入Eclipse的TOMCAT,我想當我執行「mvn clean tomcat6:run」時,maven使用自己的Tomcat插件。不過,我認爲你正在研究缺少的jar和classpath潛在的差異。我會朝那個方向挖掘。謝謝。 – Lancelot

1

想通了。我從這個web.xml中改變servlet映射:

<servlet-mapping> 
    <servlet-name>skunk</servlet-name> 
    <url-pattern>/skunk/*</url-pattern> 
    </servlet-mapping> 

這樣:

<servlet-mapping> 
    <servlet-name>skunk</servlet-name> 
    <url-pattern>/*</url-pattern> 
    </servlet-mapping> 

爲了能夠使用URL來訪問服務:

http://localhost:8080/skunk/myService 

的原來的映射,我在那裏意味着我將不得不輸入:

http://localhost:8080/skunk/skunk/myService 

達到我的服務... 嘆息

謝謝各位!

相關問題