[英]spring mvc - Separating static content from jBoss (Apache httpd upfront)
我對Spring MVC很陌生。 我要達到的目標是將Web應用程序(js,img,css)的靜態內容與jboss應用程序服務器分離。
我設法通過mod_jk成功地將Apache httpd與jboss連接起來。 我的mod_jk掛載參數如下所示:
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錯誤“資源不可用”。 有人可以幫我嗎?
還有一件事,我希望可以從/ app url獲得我的應用程序,因此在不更改web.xml的情況下,我很少看到建議這樣做的注釋。
答案是如此簡單和明顯,以至於我問了這個問題而感到羞愧。
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的每個URL
當我想設置靜態資源投放時,本教程對我有幫助:
http://www.connect-sam.com/2012/06/liferay-61-performance-tips-serving.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.