Do svého aplikačního contextu přidat
<context:mbean-export/>
(context je tento namespace xmlns:context="http://www.springframework.org/schema/context")
Pak již lze nadefinovat vlastní Mbean. (Příklad je v Kotlinu)
import org.springframework.jmx.export.annotation.ManagedOperation
import org.springframework.jmx.export.annotation.ManagedResource
import org.springframework.stereotype.Component
@Component
@ManagedResource(objectName = "MyApplicationName" + ":name=HelloMBeanWorld")
class HelloMBeanWorld {
//Its component - you can simply autowire anything
//@Autowired
//private MyBean myBean
@ManagedOperation(description = "My hello world MBean")
fun getHelloMBeanWorld(): String {
return "Hello MBean world!!!"
}
}
A pak stačí spustit aplikaci a přistupovat ke své MBean třeba pomocí JConsole. Spring už pořeší, registrovaní a hlavně taky odregistrování bean a vše. Díky Springu!
Další možnosti jsou krásně popsané v dokumentaci springu: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jmx.html
Žádné komentáře:
Okomentovat