【发布时间】:2018-12-14 20:05:25
【问题描述】:
这是我的 build.gradle...
dependencies {
compile('org.springframework.boot:spring-boot-starter-parent:2.0.1.RELEASE')
compile('org.springframework.boot:spring-boot-starter-batch')
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-web")
compile("com.h2database:h2")
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.batch:spring-batch-test')
}
我认为默认情况下会启用 JMX。我转到 JConsole,连接到应用程序并希望在 java.util.logging 下看到一个 org.springframework.boot 文件夹,但我什么也没看到。
所以,现在我挑选一些我的自定义 bean 并添加 @ManagedResource,我知道看到这些。
但是,如果我想公开像 @JobOperator 这样的 spring 批处理 bean,我该怎么做呢?
Pre Spring Boot,我可以这样:
<bean class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="spring:service=batch,bean=jobOperator">
<bean class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="jobOperator"/>
<property name="interceptorNames" value="exceptionTranslator" />
</bean>
</entry>
</map>
</property>
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
<property name="interfaceMappings">
<map>
<entry key="spring:service=batch,bean=jobOperator"
value="org.springframework.batch.core.launch.JobOperator"/>
</map>
</property>
</bean>
</property>
</bean>
当我在 Spring Boot 的 @Configuration 文件中定义我的 JobOperator 时,我会这样做:
@Bean
public JobOperator jobOperator() throws Exception {
SimpleJobOperator simpleJobOperator = new SimpleJobOperator();
// the operator wraps the launcher
simpleJobOperator.setJobLauncher(this.jobLauncher);
...
}
我无法在@Bean 注解下添加@ManagedResource。那么如何将 JobOperator 公开为 JMX bean?
【问题讨论】:
标签: spring-boot spring-batch spring-jmx