集成图控制器

如果您的应用程序是基于 Web 的(或构建在带有嵌入式 Web 容器的 Spring Boot 之上),并且 Spring 集成 HTTP 或 WebFlux 模块(分别参见 HTTP 支持WebFlux 支持)存在于类路径上,则可以使用IntegrationGraphController要公开IntegrationGraphServer功能作为 REST 服务。 为此,@EnableIntegrationGraphController@Configuration类注释和<int-http:graph-controller/>XML 元素在 HTTP 模块中可用。 与@EnableWebMvcannotation(或<mvc:annotation-driven/>对于 XML 定义),此配置会注册一个IntegrationGraphController @RestController其中@RequestMapping.path可以在@EnableIntegrationGraphControllerannotation 或<int-http:graph-controller/>元素。 默认路径为/integration.spring-doc.cadn.net.cn

IntegrationGraphController @RestController提供以下服务:spring-doc.cadn.net.cn

  • @GetMapping(name = "getGraph"):检索自上次IntegrationGraphServer刷新。 这o.s.i.support.management.graph.Graph作为@ResponseBody的 REST 服务。spring-doc.cadn.net.cn

  • @GetMapping(path = "/refresh", name = "refreshGraph"):刷新当前Graph以获取实际的运行时状态,并将其作为 REST 响应返回。 无需刷新指标的图表。 检索图形时,将实时提供这些指标。 如果自上次检索图形以来修改了应用程序上下文,则可以调用 Refresh。 在这种情况下,图形将完全重新构建。spring-doc.cadn.net.cn

您可以为IntegrationGraphController使用 Spring Security 和 Spring MVC 项目提供的标准配置选项和组件。 以下示例可实现这些目标:spring-doc.cadn.net.cn

<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 配置执行相同的作:spring-doc.cadn.net.cn

@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();
    }

    //...

}

请注意,为方便起见,@EnableIntegrationGraphControllerannotation 提供了一个allowedOrigins属性。 这提供了GET访问path. 为了更复杂,你可以使用标准的 Spring MVC 机制来配置 CORS 映射。spring-doc.cadn.net.cn