Domanda

Im quite new to spring mvc. What I'm trying to achive is separating static content of my webapp (js, img, css), from jboss app server.

I've managed to sucessfully connect apache httpd with jboss with mod_jk. My mod_jk mount params looks like this:

JkAutoAlias "/apache/httpd/root"

JkMount  /* ajp13

JkUnMount /img/* ajp3
JkUnMount /css/* ajp3
JkUnMount /js/* ajp3

Im my app, web.xml looks like this:

<?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>

And my servlet-context file:

<?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>

Now the problem is that, although the mod_jk should pass /img, /js, /css to jboss app server, it is doing this and I get nice 404 error "resource not available". Can somebody help me?

One more thing, I'd prefere to have my app available from /app url, so withouth changing web.xml, I saw few comments suggesting doing this.

È stato utile?

Soluzione

The answer is so easy and obvious that I'm actually ashamed that I asked this question...

JkAutoAlias "/apache/httpd/root"

JkMount  /* ajp13    <--- REMOVE THIS ASTERISK

JkUnMount /img/* ajp3
JkUnMount /css/* ajp3
JkUnMount /js/* ajp3

EDIT:

Or even better, just change order:

JkAutoAlias "/apache/httpd/root"

JkUnMount /img/* ajp3
JkUnMount /css/* ajp3
JkUnMount /js/* ajp3

JkMount  /* ajp13

So you wont have to remove asterisk and type every url passed to jboss

Altri suggerimenti

This tutorial helped me when I wanted to set up serving of static resources :

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top