Resource : Single location to multiple mappings - spring

When I use in my application:
<resources location="/resources/favicon.ico" mapping="/favicon.ico" />
to map out single resource.
How can I map single resource to be accessible through multiple mappings without need to duplicate the file locally ?
For example like this:
<resources location="/resources/favicon.ico" mapping="/favicon.ico" />
<resources location="/resources/favicon.ico" mapping="/favicon.png" />

You can include wildcards. mapping="/favicon.*"

Related

How can I access specific one file from resource mapping in spring

I have the following servlet mapping present -
<mvc:resources mapping="/js/**" location="/resources/js/" />
Observation:
If any web request starts with the /js request path, then it will be mapped to the resources directory, and the /** symbol indicates the recursive look for any resource files underneath the base resource directory. Here I can access js/test.js, js/test2.js
Requirement :
I want to access only one specific file(js/test.js). How can I access specific one file(js/test.js) not all files which present into /resources/js location.
Can I use below servlet mapping :::
<mvc:resources mapping="/js/test.js" location="/resources/js/" />
When you add this line
<mvc:resources mapping="/js/**" location="/resources/js/" />
Spring will add a filter rule which says
Whenever any URL with /js/** is fired, spring look for it recursively in /resources/js/ folder.
When you add following configuration
<mvc:resources mapping="/js/test.js" location="/resources/js/" />
Only URL with /js/test.js will be looked in /resources/js/ folder.
Please be mindful that any other request eg /js/jquery or js/abc will not be filtered.

Static resource mapping in Spring3

My project is implemented in Spring3 and configuration is almost xml.
Configuration of static resource mapping is like below:
<mvc:resources mapping="/a/**" location="file:/data/a/"/>
There is no problem when accessing /a/xxx.jpg but 404 Error is occurred when accessing subdirectory like /a/b/yyy.jpg. There is no problem about access authority of filesystem. How can I solve this problem? Additional configuration is needed?
(Add) Project directory is fine, but filesystem directory does not work
Use something like below :
<mvc:resources location="/" mapping="/resources/**"/>
You can specify classpath also to location any particular folder like below.
<mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/>

spring mvc touch file and serve it as resource

How can I create a file and serve it as a resource, my /src/main/webapp/WEB-INF/spring/web/dispatcherServlet-context.xml file snippet:
<mvc:resources mapping="/resources/**" location="/resources/" />
Any nice approaches?

JBOSS_HOME spring resource mapping

Hi guys I can't properly map my JBOSS_HOME location for example I have something like this:
<mvc:resources order="-10" location="file:/C:/Serwery/jboss-as-7.1.1.Final/" mapping="/test/**" />
But this is absolute path I want to make something like this:
<mvc:resources order="-10" location="file:/$JBOSS_HOME/" mapping="/test/**" />
Any advice ?
Just add this
<context:property-placeholder />
to your xml configuration where you have the <mvc:resources /> and use it like this (notice how the env variable is handled - ${JBOSS_HOME}):
<mvc:resources order="-10" location="file:/${JBOSS_HOME}/" mapping="/test/**" />

<context:property-placeholder loading from the filesystem

<context:property-placeholder ignore-unresolvable="true" location="classpath:test.properties" />
Above mentioned way of loading the property files from contex:property-placeholder works just fine. What I want to do is loading the property file from the file system.
Let's say I have the file in C drive C:\spring\test.properties. Here how can I load the file using context:property-placeholder.
Use a file: URL instead of a classpath: one
<context:property-placeholder ignore-unresolvable="true"
location="file:/C:/spring/test.properties" />
Give properties to web application(Spring based) from filesystem(External Location)
1) specify placeholder in applications root xml as
2)define enviornment name as "config" in server's context.xml and give path of file
spring.xml
file:#{contextJndi.lookup('java:comp/env/config')}
context.xml
Environment name="config" override="false" type="java.lang.String" value="D:\config.properties"/>

Resources