Answers for "how to access image in spring boot resource through file path on the browser"

0

spring boot access images in resources folder

@SpringBootApplication
public class MainApplication implements WebMvcConfigurer {

    private static Logger logger = LoggerFactory.getLogger(MainApplication.class.getName());

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        // Register resource handler for images
        registry.addResourceHandler("/images/**").addResourceLocations("/WEB-INF/images/")
                .setCacheControl(CacheControl.maxAge(2, TimeUnit.HOURS).cachePublic());
    }

    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class, args);
    }
}
Posted by: Guest on December-29-2020

Code answers related to "how to access image in spring boot resource through file path on the browser"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language