从docker容器中运行的spring应用程序将pdf作为静态资源提供服务

时间:2018-09-22 15:16:14

标签: java spring docker spring-boot pdf

当我尝试从localhost / pdfs / filename.pdf打开 Pdf文件为空白时,但是当我为图片打开该文件时(localhost / images / imagename.png) 我的应用程序正在docker容器中运行。

<script> 
document.addEventListener("DOMContentLoaded", function(event) { 
    jQuery('.ShowAllImages').click(function(){ 
        ShowAllImages();
    });
});

function ShowAllImages() {
    //Clear the page below the button
    //Create x amount of grouping sections within page
    //Create y new elementor images in those sections
    //Populate those y elementor image blocks with images   
}
</script>

文件夹{image}和pdfs都位于@Configuration public class WebMvcConfig implements WebMvcConfigurer { @Autowired private ApplicationEventPublisher publisher; @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/images/**").addResourceLocations("classpath:/static/images/").setCachePeriod(31556926); registry.addResourceHandler("/pdfs/**").addResourceLocations("classpath:/static/pdfs/").setCachePeriod(31556926); } } 文件夹中。

为什么它对图像文件有效,但对pdf文件却无效? 谢谢。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题-这是由Maven过滤资源引起的。排除* .pdf有助于解决问题:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <delimiters>
            <delimiter>@</delimiter>
        </delimiters>
        <useDefaultDelimiters>false</useDefaultDelimiters>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>