0

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.

kamil
  • 3,482
  • 1
  • 40
  • 64
  • 1st Question as it's not clear from your question. Have you copied the static resources to apache ? 2nd. Whats stopping you mounting your war in a different context ? – MikePatel Jun 22 '12 at 11:20
  • @MikePatel 1st Yes, I did yet they are unavailable 2nd Its is the way my boss want it THe problem is that mod_Jk somehow passes to jboss request for static content: `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'` – kamil Jun 22 '12 at 11:49
  • Ok. Next aren't you serving your resources from /resources/img/logo.png ? – MikePatel Jun 22 '12 at 12:35
  • Yes I'm, but I want to quit serving them there, instead I want Apache HTTPD to serv static. As far as I'm concerned, simplest upgrade of static content would required redeploy of app right? – kamil Jun 22 '12 at 12:47
  • My point is, in apache, are you serving your resources from /img or /resources/img ? – MikePatel Jun 22 '12 at 12:58
  • What do you mean by serve? If you're asking if I make a proper dirs in apache root then I did both /img and /resources/img just to be sure its working, but its not. Mod_jk still passes request to jBoss instead to serve it via apache – kamil Jun 22 '12 at 13:07

2 Answers2

1

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

kamil
  • 3,482
  • 1
  • 40
  • 64
0

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

MikePatel
  • 2,593
  • 2
  • 24
  • 38