Reputation: 241
I have a image file inside
Here is my configuration inside Configuration class.
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/**",
"classpath:/static/**", "classpath:/public/" };
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
Inside Jsp I am not able to load the image under div tag
<div id="image">
<p>
<img src="/images/reviewCount.jpg" width="600" height="400" border="0" usemap="#chart">
</p>
I tried
1) To give absolute path like src/main/resources/static/images/reviewCount.jpg
2) src="{/images}/reviewCount.jpg"
Both the approaches went in a wine.
Any one who can some shed light would be appreciated.
TIA.
regards Vinod
Upvotes: 2
Views: 11313
Reputation: 53
It is a typo. You have reviewCount.png in static/images folder and you are referring reviewCount.jpg from div tag.
Upvotes: 1
Reputation: 5871
You have to place all the images, css, js
files inside your webapp
folder.. ie webapp/resources
.
If you are packaging the application as a jar then dont use the src/main/webapp
this will only work with war packaging and it will be ignored by most build tools if you generate a jar.
In Spring boot by default, resources are mapped on /**
but you can tune that via spring.mvc.static-path-pattern
. For instance, relocating all resources to /resources/**
can be achieved as follows:
spring.mvc.static-path-pattern=/resources/**
Read more from here
Upvotes: 1
Reputation: 3299
Spring Boot automatically maps static folder in the resources to serve static content. Just put images like this:
Upvotes: 1