2012-06-22 25 views
0

對於spring mvc來說我還是個新手。我試圖實現的目標是將我的webapp(js,img,css)的靜態內容從jboss應用服務器中分離出來。spring mvc - 從jBoss中分離出靜​​態內容(Apache httpd upfront)

我已經設法成功地與mod_jk的JBoss的連接apache httpd的。我的mod_jk安裝這樣的PARAMS外觀:

JkAutoAlias "/apache/httpd/root" 

JkMount /* ajp13 

JkUnMount /img/* ajp3 
JkUnMount /css/* ajp3 
JkUnMount /js/* ajp3 

林我的應用程序,web.xml文件看起來是這樣的:

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

<!-- Root-context is empty --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/spring/root-context.xml</param-value> 
</context-param> 


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

<servlet> 
    <servlet-name>appServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

</web-app> 

而且我的servlet上下文文件:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
    "> 

<mvc:annotation-driven/> 

<mvc:resources mapping="/resources/**" location="/resources/"/> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/pages/"/> 
    <property name="suffix" value=".jsp"/> 
</bean> 
<context:component-scan base-package="com.execon"/> 

<bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basename" value="classpath:messages"/> 
    <property name="defaultEncoding" value="UTF-8"/> 
</bean> 

</beans> 

現在的問題是的,儘管mod_jk應該將/ img,/ js,/ css傳遞給jboss應用服務器,但它正在這樣做,並且我得到了很好的404錯誤「資源不可用」。有人能幫助我嗎?

還有一兩件事,我會prefere有我的應用程序可以從/應用程序網址,所以withouth的改變web.xml中,我看到一些評論建議這樣做。

+0

1提問每個URL,因爲它不是從你的問題不清楚。你有沒有將靜態資源複製到Apache?第2位。什麼阻止你在不同的環境中進行戰爭? – MikePatel

+0

@MikePatel 月1日是的,我確實還沒有它們不可 第二它的方式是我的老闆希望它 的問題是,不知何故MOD_JK傳遞到JBoss靜態內容的請求: '13:50:40491警告[ org.springframework.web.servlet.PageNotFound](AJP - 127.0.0.1-8009-2)未發現與URI [/img/logo.png]在DispatcherServlet的名爲「HTTP請求映射appServlet'' – kamil

+0

確定。接下來是不是從/resources/img/logo.png提供資源? – MikePatel

回答

1

答案是如此簡單和明顯,實際上,我慚愧,我問這個問題...

JkAutoAlias "/apache/httpd/root" 

JkMount /* ajp13 <--- REMOVE THIS ASTERISK 

JkUnMount /img/* ajp3 
JkUnMount /css/* ajp3 
JkUnMount /js/* ajp3 

編輯:

甚至更​​好,只是改變順序:

JkAutoAlias "/apache/httpd/root" 

JkUnMount /img/* ajp3 
JkUnMount /css/* ajp3 
JkUnMount /js/* ajp3 

JkMount /* ajp13 

所以你不會有刪除星號,並輸入傳遞到JBoss