作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 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
关于java - spring mvc - 将静态内容与 jBoss 分离(Apache httpd 前期),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154792/
我对 spring mvc 很陌生。我想要实现的目标是将我的 web 应用程序的静态内容(js、img、css)与 jboss 应用程序服务器分离。 我已经成功使用 mod_jk 连接 apache
我是一名优秀的程序员,十分优秀!