Javi
Javi

Reputation: 19769

Getting a Spring resource

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

My application looks like this:

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.

Upvotes: 1

Views: 1744

Answers (2)

Arne Burmeister
Arne Burmeister

Reputation: 20594

What about new ClassPathResource("/resources/style/myCSS.css")?

Upvotes: 0

Bozho
Bozho

Reputation: 597076

There is ServletContextResource. You can construct it passing the ServletContext and the relative path.

Upvotes: 2

Related Questions