Getting a Spring resource

Posted by Javi on Stack Overflow See other posts from Stack Overflow or by Javi
Published on 2010-02-17T11:25:25Z Indexed on 2010/04/14 4:53 UTC
Read the original article Hit count: 385

Filed under:
|
|
|

Hello,

I'm trying to read a css file with the Resources provided by Spring.

My application looks like this:

  • src
    • src/com herer my classes inside packages
  • WebContent
    • WebContent/resources/style/myCSS.css --> the css I want to read
    • WebContent/WEB-INF --> here is my application-context.xml

I can get the css and read it by doing something like this:

UrlResource file = new UrlResource("http://localhost:8080/myApp/resources/style/myCSS.css");

but it depends on the server and aplication names. I've tried to do it by other implementations of Resource Interface, but the file is not found cause I can't find out how to wite the path. I've tried with this:

FileSystemResource file = new FileSystemResource("/WebContent/resources/style/myCSS.css");

I also tried with wildcards, but it doesn't find the file either.

ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath*:/WEB-INF/application-context-core.xml");
Resource file = ctx.getResource("file:**/myCSS.css");

How should I write the path to get the css.

Thanks.

© Stack Overflow or respective owner

Related posts about spring

Related posts about resources