对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

如果您的应用程序是基于 Web 的(或基于嵌入式 Web 容器构建在 Spring Boot 之上),并且类路径上存在 Spring Integration HTTP 或 WebFlux 模块(分别参见 HTTP 支持WebFlux 支持),则可以使用 a 将该功能公开为 REST 服务。 为此,HTTP 模块中提供了 and 类注释和 XML 元素。 与注释(或对于 XML 定义)一起,此配置注册一个可以在注释或元素上配置的位置。 默认路径为 。IntegrationGraphControllerIntegrationGraphServer@EnableIntegrationGraphController@Configuration<int-http:graph-controller/>@EnableWebMvc<mvc:annotation-driven/>IntegrationGraphController@RestController@RequestMapping.path@EnableIntegrationGraphController<int-http:graph-controller/>/integrationSpring中文文档

提供以下服务:IntegrationGraphController@RestControllerSpring中文文档

  • @GetMapping(name = "getGraph"):检索自上次刷新以来 Spring Integration 组件的状态。 作为 REST 服务的 a 返回。IntegrationGraphServero.s.i.support.management.graph.Graph@ResponseBodySpring中文文档

  • @GetMapping(path = "/refresh", name = "refreshGraph"):刷新实际运行时状态的当前状态,并将其作为 REST 响应返回。 无需刷新指标的图表。 它们在检索图形时实时提供。 如果自上次检索图形以来已修改应用程序上下文,则可以调用刷新。 在这种情况下,图形将完全重建。GraphSpring中文文档

您可以使用 Spring Security 和 Spring MVC 项目提供的标准配置选项和组件设置安全性和跨域限制。 以下示例实现了这些目标:IntegrationGraphControllerSpring中文文档

<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中文文档

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

    //...

}

请注意,为方便起见,批注提供了一个属性。 这提供了对 . 为了更复杂,您可以使用标准的 Spring MVC 机制配置 CORS 映射。@EnableIntegrationGraphControllerallowedOriginsGETpathSpring中文文档