You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JHipster微前端remoteEntry.js 404错误排查求助

问题排查与解决方案

针对你遇到的网关加载微服务remoteEntry.js返回404的问题,以下是具体排查步骤和修复方案:

1. 验证微服务前端资源可用性

  • 每个微服务(CaplCommon、CaplLap)必须先执行npm run build,确保dist目录下生成remoteEntry.js文件。
  • 直接访问微服务前端的remoteEntry.js地址(比如http://localhost:9004/remoteEntry.js),确认能正常返回文件。如果无法访问:
    • 检查微服务的npm start命令是否指定了正确端口,查看package.json中的start配置,比如:
      "start": "ng serve --port 9004"
      
    • 确认微服务Spring Boot配置中映射了静态资源路径,在application.yml添加:
      spring:
        web:
          resources:
            static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:./dist/
      

2. 检查网关服务发现与路由配置

  • 登录Consul UI(默认http://localhost:8500),确认CaplCommon、CaplLap服务已注册且状态为healthy。
  • 网关application.yml需配置正确的服务路由,确保将/services/caplcommon/**请求转发到对应微服务:
    spring:
      cloud:
        gateway:
          routes:
            - id: caplcommon-service
              uri: lb://CAPLCOMMON
              predicates:
                - Path=/services/caplcommon/**
              filters:
                - RewritePath=/services/caplcommon/(?<path>.*), /$\{path}
            - id: capllap-service
              uri: lb://CAPLLAP
              predicates:
                - Path=/services/capllap/**
              filters:
                - RewritePath=/services/capllap/(?<path>.*), /$\{path}
        consul:
          discovery:
            enabled: true
    

3. 确认模块联邦配置正确性

  • 微服务的Webpack配置(webpack.dev.js/webpack.prod.js)中,ModuleFederationPlugin需设置正确的name和filename:
    new ModuleFederationPlugin({
      name: 'caplcommon',
      filename: 'remoteEntry.js',
      exposes: {
        './Entities': './src/app/entities/entities.module.ts',
      },
      shared: share({
        '@angular/core': { singleton: true, strictVersion: true, requiredVersion: 'auto' },
        // 其他共享依赖配置
      })
    })
    
  • 网关的Webpack配置中,remotes需正确指向微服务的remoteEntry.js地址,确保端口和服务名无拼写错误:
    new ModuleFederationPlugin({
      remotes: {
        caplcommon: 'caplcommon@http://localhost:9004/remoteEntry.js',
        capllap: 'capllap@http://localhost:<CaplLap端口>/remoteEntry.js',
      },
      // 其他配置
    })
    

4. 确认启动顺序

严格按照以下顺序启动服务:

  1. Docker中的Consul服务
  2. CaplCommon、CaplLap的Spring Boot后端
  3. CaplCommon、CaplLap的前端(执行npm start)
  4. 网关CaplWorkbook的Spring Boot后端
  5. 网关CaplWorkbook的前端(执行npm start)

内容的提问来源于stack exchange,提问作者Mark Wright

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 00:42:36