how to get image directory in spring boot from static code example

Example: 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);
    }
}

Tags:

Java Example