我在Spring Boot应用程序(称为服务工作流(中嵌入了一个Camunda实例,该应用程序在动态端口上启动,并通过Eureka向Spring Cloud注册。
Camunda服务的主要类别很简单:
@EnableDiscoveryClient
@SpringBootApplication
@EnableConfigurationProperties(ServiceContextConfig.class)
public class WorkflowServiceApplication {
public static void main(String[] args) {
SpringApplication.run(WorkflowServiceApplication.class, args);
}
}
以及配置属性:
server.port=0
eureka.client.healthcheck.enabled=true
这些服务位于本地Spring Cloud Gateway后面,该网关运行在使用Eureka注册主机的端口上,并且可以通过http://localhost:8080
网关的代码是:
@SpringBootApplication
@EnableDiscoveryClient
public class GatewayServiceApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayServiceApplication.class, args);
}
}
以及配置属性:
server.port=8080
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true
没有定义路线——它完全依靠尤里卡来找到路线。这对REST连接没有问题。
任何使用runtimeService的客户端都可以使用以下URL的false启动工作流:foreign.client.config.remoteRuntimeService.url=服务工作流/rest/
因此,可以通过RESTAPI的网关URL访问工作流服务。
当Camunda服务启动并分配到端口x时,我可以通过以下方式查看驾驶舱http://localhost:x/app/cockpit/default/但是如果我尝试通过网关。,http://localhost:8080/service-工作流/app/驾驶舱/default/它无法返回任何CSS文件-网关日志显示:
2020-09-25 16:46:00,454 DEBUG [reactor-http-nio-2] reactor.netty.http.server.HttpServer (Loggers.java:254) - [id: 0xe08516d1, L:/0:0:0:0:0:0:0:1:8080 - R:/0:0:0:0:0:0:0:1:61018] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@74cedfb5
2020-09-25 16:46:00,453 DEBUG [reactor-http-nio-8] org.springframework.web.server.adapter.HttpWebHandlerAdapter (LogFormatUtils.java:91) - [9407161c-27] HTTP GET "/app/cockpit/styles/styles.css?bust=7.12.0"
2020-09-25 16:46:00,456 DEBUG [reactor-http-nio-2] org.springframework.web.server.adapter.HttpWebHandlerAdapter (LogFormatUtils.java:91) - [e08516d1-28] HTTP GET "/app/cockpit/styles/user-styles.css?bust=7.12.0"
2020-09-25 16:46:00,455 DEBUG [reactor-http-nio-7] reactor.netty.http.server.HttpServer (Loggers.java:254) - [id: 0x125a09dc, L:/0:0:0:0:0:0:0:1:8080 - R:/0:0:0:0:0:0:0:1:61253] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@74cedfb5
2020-09-25 16:46:00,458 DEBUG [reactor-http-nio-8] org.springframework.web.reactive.handler.SimpleUrlHandlerMapping (AbstractHandlerMapping.java:183) - [9407161c-27] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2020-09-25 16:46:00,460 DEBUG [reactor-http-nio-7] org.springframework.web.server.adapter.HttpWebHandlerAdapter (LogFormatUtils.java:91) - [125a09dc-29] HTTP GET "/app/cockpit/styles/styles-components.css?bust=7.12.0"
2020-09-25 16:46:00,460 DEBUG [reactor-http-nio-2] org.springframework.web.reactive.handler.SimpleUrlHandlerMapping (AbstractHandlerMapping.java:183) - [e08516d1-28] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2020-09-25 16:46:00,463 DEBUG [reactor-http-nio-8] org.springframework.web.reactive.resource.ResourceWebHandler (ResourceWebHandler.java:324) - [9407161c-27] Resource not found
2020-09-25 16:46:00,464 DEBUG [reactor-http-nio-7] org.springframework.web.reactive.handler.SimpleUrlHandlerMapping (AbstractHandlerMapping.java:183) - [125a09dc-29] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"]
2020-09-25 16:46:00,465 DEBUG [reactor-http-nio-2] org.springframework.web.reactive.resource.ResourceWebHandler (ResourceWebHandler.java:324) - [e08516d1-28] Resource not found
2020-09-25 16:46:00,466 DEBUG [reactor-http-nio-7] org.springframework.web.reactive.resource.ResourceWebHandler (ResourceWebHandler.java:324) - [125a09dc-29] Resource not found
2020-09-25 16:46:00,469 DEBUG [reactor-http-nio-2] org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler (CompositeLog.java:147) - [e08516d1-28] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /app/cockpit/styles/user-styles.css
2020-09-25 16:46:00,468 DEBUG [reactor-http-nio-8] org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler (CompositeLog.java:147) - [9407161c-27] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /app/cockpit/styles/styles.css
2020-09-25 16:46:00,476 DEBUG [reactor-http-nio-2] org.springframework.core.codec.CharSequenceEncoder (CompositeLog.java:147) - [e08516d1-28] Writing "<html><body><h1>Whitelabel Error Page</h1><p>This application has no configured error view, so you (truncated)...
2020-09-25 16:46:00,479 DEBUG [reactor-http-nio-7] org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler (CompositeLog.java:147) - [125a09dc-29] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /app/cockpit/styles/styles-components.css
2020-09-25 16:46:00,477 DEBUG [reactor-http-nio-8] org.springframework.core.codec.CharSequenceEncoder (CompositeLog.java:147) - [9407161c-27] Writing "<html><body><h1>Whitelabel Error Page</h1><p>This application has no configured error view, so you (truncated)...
2020-09-25 16:46:00,480 DEBUG [reactor-http-nio-7] org.springframework.core.codec.CharSequenceEncoder (CompositeLog.java:147) - [125a09dc-29] Writing "<html><body><h1>Whitelabel Error Page</h1><p>This application has no configured error view, so you (truncated)...
2020-09-25 16:46:00,480 DEBUG [reactor-http-nio-2] reactor.netty.http.server.HttpServerOperations (Loggers.java:254) - [id: 0xe08516d1, L:/0:0:0:0:0:0:0:1:8080 - R:/0:0:0:0:0:0:0:1:61018] Decreasing pending responses, now 0
我最终解决这个问题的方法是在网关中添加一个自定义路由:
.route("camunda", r -> r.path("/camunda/**")
//.filters(f -> f.rewritePath("/report/(?<segment>.*)", "/${segment}"))
.uri("lb://my-camunda-service"))