这是我的 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,连接到应用程序并期望在org.springframework.boot
下看到一个文件夹java.util.logging
,但我什么也没看到。
所以,现在我挑选了一些我的自定义 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>
当我定义我的 JobOperator 时,我在 Spring Boot 的 @Configuration 文件中执行以下操作:
@Bean
public JobOperator jobOperator() throws Exception {
SimpleJobOperator simpleJobOperator = new SimpleJobOperator();
// the operator wraps the launcher
simpleJobOperator.setJobLauncher(this.jobLauncher);
...
}
我无法在@Bean 注释下添加@ManagedResource。那么如何将 JobOperator 公开为 JMX bean?