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