0

我对spring mvc很陌生。我想要实现的是从 jboss 应用服务器中分离出我的 webapp(js、img、css)的静态内容。

我已经成功地将 apache httpd 与 jboss 与 mod_jk 连接起来。我的 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-context 文件:

<?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 的情况下,我看到很少有评论建议这样做。

4

2 回答 2

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 的每个 url

于 2012-06-22T13:33:54.880 回答
0

当我想设置静态资源服务时,本教程帮助了我:

http://www.connect-sam.com/2012/06/liferay-61-performance-tips-serving.html

于 2012-06-22T11:06:42.640 回答