最后,我使代码工作了!感谢@pan提到根路径上的Zuul路由问题,以及@RzvRazvan揭示了Zuul路由的工作方式。
我刚刚将 控制器添加到具有一个端点的Zuul路由网关微服务,以从根重定向
http://localhost:8080/到
http://localhost:8080/ui/:
@Controllerpublic class GateController { @GetMapping(value = "/") public String redirect() { return "forward:/ui/"; } }Zuul 从重定向特性 网关的microService 端口 8080 作为
http://localhost:8080/ui/对
UI微服务 ,其实现端口隔离的弹簧启动应用程序 8090 为
http://localhost:8090/ui/:
zuul: routes: ui: path: /ui/** serviceId: myproject.service.ui stripPrefix: false sensitiveHeaders:
UI微服务的属性:
server: port: 8090 servlet: contextPath: /ui
最终,此调用
http://localhost:8080/将我们重定向到UI微服务的控制器,该控制器返回view
index.html:
@Controllerpublic class UiController { @GetMapping(value = "/") public String index() { return "index.html"; }}实际上,在这样的体系结构中呈现静态内容时,我还有另一个问题,但它与我使用Vue.js框架开发的前端配置有关。如果可能对某人有帮助,我将在这里用几句话进行描述。
我具有UI微服务的以下文件夹结构:
myproject.service.ui └───src/main/resources └───public |───static | ├───css | └───js └───index.html
public文件夹的所有内容都是由
npm run build任务从 webpack 和 vue.js
生成的。第一次,我打电话给
http://localhost:8080/我 200 OK 了
index.html和 404
的所有其他静态资源,因为他们被称为是这样的:
http:\localhost:8080staticjssome.js
因此,它为webpack中的静态资产配置了错误的公共路径。我在中更改了它
configindex.js:
module.exports = { ... build: { ... assetsPublicPath: '/ui/', ... }...}静态资产也因此得到适当的称呼。例如:
http:\localhost:8080uistaticjssome.js



