spring - 如何在带有tomcat的spring mvc maven应用程序中提供来自外部war文件的静态数据

标签 spring spring-mvc tomcat amazon-ec2 static-content

您好,我用 spring mvc 框架创建了一个 maven web 应用程序,我创建了 war 文件,也部署在 amazon web 服务器中,因为有很多静态文件,如 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.comhttps://cdnjs.cloudflare.comhttps://cdn.rawgit.comhttps://yandex.st)用于 Bootstrap、jQuery 等静态资源。

关于spring - 如何在带有tomcat的spring mvc maven应用程序中提供来自外部war文件的静态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46542429/

相关文章:

java - Spring Boot中取消授权

java - Spring bean 和应用程序生命周期中更改 bean 参数

java - HystrixCommand 注释导致 ControllerLinkBuilder 中断

java - Resttemplate 没有正确反序列化 JSON

java - 如何在 Multi-Tenancy 架构中维护 session 属性?

php - 在同一个文件中同时执行 PHP 和 JSP?

java - IntelliJ Idea 12 无法运行/部署 Web 应用程序

spring - 如何在 HandlerInterceptorAdapter 中使用 @ResponseBody 记录 Spring 3 Controller 的 JSON 响应?

java - 使用 Controller -> 服务 -> 存储库对 Spring Boot 进行单元测试