【发布时间】:2012-06-24 16:04:07
【问题描述】:
我对 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 的情况下,我看到很少有 cmets 建议这样做。
【问题讨论】:
-
第一个问题,因为您的问题并不清楚。您是否将静态资源复制到 apache ?第二。是什么阻止你在不同的环境中展开你的战争?
-
@MikePatel 1st 是的,我做了但他们不可用 2nd 这是我老板想要的方式问题是 mod_Jk 以某种方式传递给 jboss 请求静态内容:
13:50:40,491 WARN [org.springframework.web.servlet.PageNotFound] (ajp--127.0.0.1-8009-2) No mapping found for HTTP request with URI [/img/logo.png] in DispatcherServlet with name 'appServlet' -
好的。接下来你不是从 /resources/img/logo.png 提供你的资源吗?
-
是的,我是,但我想停止在那里为它们提供服务,而是希望 Apache HTTPD 提供静态服务。就我而言,最简单的静态内容升级需要重新部署应用程序,对吗?
-
我的意思是,在 apache 中,您是从 /img 还是 /resources/img 提供资源?
标签: java apache spring-mvc jboss mod-jk