Methew
Methew

Reputation: 415

Spring boot web application can't find image in WEB-INF

This is my project content structure:

this is my project content structure

The spring boot applicaton, InternalResourceViewResolver is pointed to the jsp resource:

spring boot applicaton

This is the login.jsp, and the background tag can't load the image in WEB-INF/jsp/Image, but in spring boot application.java, I had pointed the resource. How can I get it?

the login jsp

Upvotes: 0

Views: 4317

Answers (2)

Denys
Denys

Reputation: 1478

I had same issue. I understand that all static resources should be located in /resources/static or public location (as per Spring documentation) but it didn't work.

I implemented my own WebMvcConfigurerAdapter like this:

@Configuration
public class CustomResourceConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("");
    }
}

Now it works. Hope it can help to somebody.

Upvotes: 0

Prashant Saraswat
Prashant Saraswat

Reputation: 848

The path of the image is relative to the URL, not relative to the location of the JSP. Try putting the image here: src/main/webapp/Images/LoginBg.jpg

Upvotes: 4

Related Questions