gpt4 book ai didi

java - spring mvc - 将静态内容与 jBoss 分离(Apache httpd 前期)

转载 作者:行者123 更新时间:2023-12-01 15:19:31 24 4
gpt4 key购买 nike

我对 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com