2012-06-22 24 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