好的,我自己找到了:-)
在 Spring boot 中,您可以使用此自定义程序自定义 servlet 容器并在其中添加新的 mimetype。
(更新)
春季启动 2.x:
@Component
public class ServletCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
@Override
public void customize(TomcatServletWebServerFactory factory) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("woff", "application/x-font-woff");
factory.setMimeMappings(mappings);
}
}
春季启动 1.x:
@Component
public class ServletCustomizer implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("woff","application/font-woff");
mappings.add("woff2","application/font-woff2");
container.setMimeMappings(mappings);
}
}