如何使用 tomcat 在 spring mvc maven 应用程序中从外部 war 文件提供静态数据

How to serve static data from outside war file in spring mvc maven application with tomcat

您好,我用 spring mvc 框架创建了一个 maven web 应用程序,我创建了 war 文件,因为有很多静态文件,例如 bootstrap css 和 js 文件以及其他,war 文件很重,加载第一页需要花费太多时间。 war 文件臃肿,如何从 war 中分离出静​​态文件,例如 bootstrap?我该如何解决这个问题?

because of lots of static files like bootstrap css and js file and other, the war file is heavy and its taking too much time to load first page I'm not sure that heavy war file is a reason why a page is loading slow. There are tons of reasons that can cause such behavior. I'd suggest to look closer on that first.

how to separate out static files, such as bootstrap from your war?

Spring MVC 可以配置为从文件系统提供静态资产:

这是一个例子:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
      .addResourceHandler("/files/**")
      .addResourceLocations("file:/opt/files/");
 }

可以在此处找到更多示例和解释:http://www.baeldung.com/spring-mvc-static-resources

how do I resolve this problem?

我正在使用 public CDN 服务器 (https://maxcdn.bootstrapcdn.com, https://cdnjs.cloudflare.com, https://cdn.rawgit.com, https://yandex.st) 作为静态资源,例如 Bootstrap、jQuery 等