Skip to main content

JAWR and Spring 3 using annotation driven configuration

  4 posts   Feedicon  
Replies: 3 - Last Post: February 25, 2012 16:12
by: icefox
showing 1 - 4 of 4
Posted: February 17, 2012 22:43 by LightningMan
I have been trying to get JAWR to work with my Spring 3 application. Using the following in my Spring xml file I cannot get to any of the files with debug turned on or debug turned off.
<!-- Base Jawr config -->
<bean abstract="true" id="jawrBase" class="net.jawr.web.servlet.JawrSpringController">
    <property name="configLocation" value="/" />
    <!-- This must match the controller mapping prefix to which the jawr controllers are
           bound at the urlMapping bean  -->
    <property name="controllerMapping" value="/resources/"/>

<!-- JavaScript Controller -->
<bean id="jawrJsController" parent="jawrBase" />

<bean id="urlMapping" 
     <property name="mappings">
               <prop key="/resources/**/*.js">jawrJsController</prop>

Then I removed the prefix "/resources" and commented out the controller mapping in jawrBase and then I can get to the files using debug mode but I cannot get to to the bundles in production mode. I'm getting 404 errors.

Example of working links in debug mode:
<script type="text/javascript">/* Start adding members resolved by '/files/a.js'. Bundle id is: '/bundles/test.js' */</script>
<script type="text/javascript" src="/project/files/a.js?d=933316521" ></script>
<script type="text/javascript">/* Finished adding members resolved by /files/a.js */</script>

<script type="text/javascript">/* Start adding members resolved by '/files/test-dash/b.js'. Bundle id is: '/bundles/test2.js' */</script>
<script type="text/javascript" src="/project/files/test-dash/b.js?d=2096705249" ></script>
<script type="text/javascript" src="/project/files/test-dash/har/c.js?d=128254447" ></script>
<script type="text/javascript">/* Finished adding members resolved by /files/test-dash/b.js */</script

Example of non-working links in production mode:
<script type="text/javascript" src="/project/gzip_1437180051/bundles/lib.js" ></script>
<script type="text/javascript" src="/project/gzip_N1600380113/bundles/help.js" ></script>
<script type="text/javascript" src="/project/gzip_N1589687647/bundles/test.js" ></script>
<script type="text/javascript" src="/project/gzip_988427574/bundles/test2.js" ></script>

My properties file looks like this:
#Common properties

# All files within /js/lib will be together in a bundle. 
# The remaining scripts will be served separately.

On a side note, I also found that the files in /WEB-INF/ are never available, but I can move the files, not sure if this is a tomcat or Jawr issue though.

Finally here is the code in my JSP file for referencing the items.
<jwr:script src="/files/a.js"></jwr:script>
<jwr:script src="/files/test-dash/b.js"></jwr:script>
<jwr:script src="/files/test-dash/c.js"></jwr:script>

Can you please tell me what I'm doing wrong and how I can get JAWR and Spring 3 to play nice together? Ideally I would like to use the prefix but that isn't 100% required.
Posted: February 21, 2012 21:15 by icefox

It seems strange that it works in debug mode only.
Have you check the sample application available at : jawr/samples/java/jawrSpringMVCSample

About the acces of resources in WEB-INF directory, for security reason, it has been decided to not allow Jawr to serve any resources from WEB-INF directory.
You must place your resources on the standard web app directory.

Posted: February 22, 2012 23:42 by LightningMan
Hi icefox,

I just tried the sample application and it works. Then I was trying to it to be closer to how my app is and I found that it is using Spring 2.0.2 and we are using Spring 3.1. I wasn't able to update the pom.xml file to pull down a 3.1 version. So not sure if the problem exists there. Do you know of anyone that has tried and got it JAWR working with Spring 3.0/3.1 and that is using the <mvc:annotation-driven> statement?

Is there a way to turn on some more debugging that may help figure out what is going on here?

Posted: February 25, 2012 16:12 by icefox

Unfortnately I'm not aware of anyone who work with Jawr and the Spring 3.0/3.1 and the MVC annotation.
I think that the easiest way to figure out what's going on, is to get the source code of Jawr and to launch your server
in debug mode.

Replies: 3 - Last Post: February 25, 2012 16:12
by: icefox
Please Confirm