【问题标题】:How does the JHipster/Angular configuration determines that it needs to use the index.html file?JHipster/Angular 配置如何确定它需要使用 index.html 文件?
【发布时间】:2015-06-22 14:36:24
【问题描述】:

我刚刚使用 JHipster 生成了一个 Spring/Angular 应用程序。

我使用此 URL 成功访问了主页:http://localhost:8080,该 URL 重定向到 http://localhost:8080/#/,并且正确加载了 index.html 文件。

我不确定 Angular 和浏览器如何确定它们需要加载 index.html 文件。

这是在 JHipster 应用程序中的哪里配置的?

编辑:是否有一些“默认主页”配置?

【问题讨论】:

    标签: angularjs spring-mvc jhipster


    【解决方案1】:

    我使用此 URL 成功访问了主页: http://localhost:8080 重定向到 http://localhost:8080/#/

    对服务器的请求是针对“/”的,并且提供了 index.html。 “/#/”是 index.html 页面上的 javascript 启动时发生的所有客户端内容(Angular 路由),而不是服务器端重定向的结果。

    这是在 JHipster 应用程序中的哪里配置的?

    这是 Spring Boot 的默认设置,不是 JHipster 特有的。来自Spring Boot docs

    自动配置在 Spring 的基础上添加了以下功能 默认值:

    • 静态 index.html 支持。

    默认情况下,Spring Boot 将提供目录中的静态内容 在中称为 /static(或 /public 或 /resources 或 /META-INF/resources) 类路径或 ServletContext 的根目录。它使用 来自 Spring MVC 的 ResourceHttpRequestHandler,因此您可以修改它 通过添加您自己的 WebMvcConfigurerAdapter 并覆盖 addResourceHandlers 方法。

    我认为这不能通过属性文件或类似的东西进行配置,您必须编写一些代码。请参阅answer to this question

    【讨论】:

    • 非常感谢约翰!
    • 相关代码可以在org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration类中找到。
    猜你喜欢
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    相关资源
    最近更新 更多