|
如需使用最新稳定版本,请使用 Spring Integration 7.0.4! |
集成图控制器
如果您的应用程序是基于 Web 的(或构建在带有嵌入式 Web 容器的 Spring Boot 之上),并且类路径中存在 Spring Integration HTTP 或 WebFlux 模块(请分别参见 HTTP 支持 和 WebFlux 支持),则可以使用 IntegrationGraphController 将 IntegrationGraphServer 功能作为 REST 服务公开。
为此,HTTP 模块中提供了 @EnableIntegrationGraphController 和 @Configuration 类注解以及 <int-http:graph-controller/> XML 元素。
结合 @EnableWebMvc 注解(或用于 XML 定义的 <mvc:annotation-driven/>),此配置会注册一个 IntegrationGraphController @RestController,其 @RequestMapping.path 可在 @EnableIntegrationGraphController 注解或 <int-http:graph-controller/> 元素上进行配置。
默认路径为 /integration。
The IntegrationGraphController @RestController 提供以下服务:
-
@GetMapping(name = "getGraph"): 用于检索自上次IntegrationGraphServer刷新以来 Spring Integration 组件的状态。o.s.i.support.management.graph.Graph作为 REST 服务的@ResponseBody返回。 -
@GetMapping(path = "/refresh", name = "refreshGraph"): 刷新当前Graph以获取实际运行时状态,并将其作为 REST 响应返回。 无需为指标刷新图表。 在检索图表时,它们会实时提供。 如果自上次检索图表以来应用上下文已修改,则可以调用刷新操作。 在这种情况下,图表将被完全重建。
您可以使用 Spring Security 和 Spring MVC 项目提供的标准配置选项和组件,为 IntegrationGraphController 设置安全性和跨源限制。
以下示例实现了这些目标:
<mvc:annotation-driven />
<mvc:cors>
<mvc:mapping path="/myIntegration/**"
allowed-origins="http://localhost:9090"
allowed-methods="GET" />
</mvc:cors>
<security:http>
<security:intercept-url pattern="/myIntegration/**" access="ROLE_ADMIN" />
</security:http>
<int-http:graph-controller path="/myIntegration" />
以下示例展示了如何使用 Java 配置实现相同的功能:
@Configuration
@EnableWebMvc // or @EnableWebFlux
@EnableWebSecurity // or @EnableWebFluxSecurity
@EnableIntegration
@EnableIntegrationGraphController(path = "/testIntegration", allowedOrigins="http://localhost:9090")
public class IntegrationConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/testIntegration/**").hasRole("ADMIN")
// ...
.formLogin();
}
//...
}
请注意,为了方便起见,@EnableIntegrationGraphController 注解提供了 allowedOrigins 属性。
这提供了对 path 的 GET 访问权限。
对于更复杂的需求,您可以使用标准的 Spring MVC 机制来配置 CORS 映射。