集成图控制器
如果您的应用程序是基于 Web 的(或构建在带有嵌入式 Web 容器的 Spring Boot 之上),并且 Spring 集成 HTTP 或 WebFlux 模块(分别参见 HTTP 支持和 WebFlux 支持)存在于类路径上,则可以使用IntegrationGraphController
要公开IntegrationGraphServer
功能作为 REST 服务。
为此,@EnableIntegrationGraphController
和@Configuration
类注释和<int-http:graph-controller/>
XML 元素在 HTTP 模块中可用。
与@EnableWebMvc
annotation(或<mvc:annotation-driven/>
对于 XML 定义),此配置会注册一个IntegrationGraphController
@RestController
其中@RequestMapping.path
可以在@EnableIntegrationGraphController
annotation 或<int-http:graph-controller/>
元素。
默认路径为/integration
.
这IntegrationGraphController
@RestController
提供以下服务:
-
@GetMapping(name = "getGraph")
:检索自上次IntegrationGraphServer
刷新。 这o.s.i.support.management.graph.Graph
作为@ResponseBody
的 REST 服务。 -
@GetMapping(path = "/refresh", name = "refreshGraph")
:刷新当前Graph
以获取实际的运行时状态,并将其作为 REST 响应返回。 无需刷新指标的图表。 检索图形时,将实时提供这些指标。 如果自上次检索图形以来修改了应用程序上下文,则可以调用 Refresh。 在这种情况下,图形将完全重新构建。
您可以为IntegrationGraphController
使用 Spring Security 和 Spring MVC 项目提供的标准配置选项和组件。
以下示例可实现这些目标:
<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
annotation 提供了一个allowedOrigins
属性。
这提供了GET
访问path
.
为了更复杂,你可以使用标准的 Spring MVC 机制来配置 CORS 映射。