I have a spring boot application with built-in Tomcat. I wanted to put some image files and folders from another place through the tomcat directory list. So I added the following in the configuration file
public class AppConfig extends WebMvcConfigurerAdapter
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**").addResourceLocations("file:///xxx/yyy/images/");
}
}
Now I can access individual images if I know the name.
Example: localhost: 8080 / images / file.jpg.
But since the default directory list is incorrect, I cannot access the image list through "localhost: 8080 / images /" to find out all available images.
I tried the option below to add lists, but didn't work.
public class MyApplication implements ServletContextInitializer{
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setInitParameter("listings", "true");
}
}
source
share