Java Code Examples for org.springframework.jmx.export.MBeanExporter#getServer()
The following examples show how to use
org.springframework.jmx.export.MBeanExporter#getServer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringMBeanServerBeanBootstrap.java From thinking-in-spring-boot-samples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); // 注册当前 Class context.register(SpringMBeanServerBeanBootstrap.class); // 启动应用上下文 context.refresh(); // 获取名为 "mBeanExporter" Bean,来自于 mBeanExporter() 方法 @Bean 定义 MBeanExporter mBeanExporter = context.getBean("mBeanExporter", MBeanExporter.class); // 获取名为 "mBeanServer" Bean,来自于 mBeanServer() 方法 @Bean 定义 MBeanServer mBeanServer = context.getBean("mBeanServer", MBeanServer.class); // 从 "mBeanExporter" Bean 中获取来自于其afterPropertiesSet()方法创建 "mBeanServer" 对象 MBeanServer mBeanServerFromMBeanExporter = mBeanExporter.getServer(); System.out.printf("来自 mBeanExporter Bean 关联的 MBeanServer 实例是否等于平台 MBeanServer : %b \n", mBeanServerFromMBeanExporter == ManagementFactory.getPlatformMBeanServer() ); System.out.printf("来自 mBeanExporter Bean 关联的 MBeanServer 实例是否等于 mBeanServer Bean : %b \n", mBeanServerFromMBeanExporter == mBeanServer ); // 关闭应用上下文 context.close(); }
Example 2
Source File: SpringMBeanExporterBootstrap.java From thinking-in-spring-boot-samples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { // 创造 MBeanServer 对象 MBeanServer mBeanServerFromCreate = MBeanServerFactory.createMBeanServer(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); // 注册 SpringMBeanExporterBootstrap context.register(SpringMBeanExporterBootstrap.class); // 启动应用上下文 context.refresh(); // 获取 "mBeanExporter" Bean MBeanExporter mBeanExporter = context.getBean("mBeanExporter", MBeanExporter.class); // 从 "mBeanExporter" Bean 获取 MBeanServer MBeanServer mBeanServerFromBean = mBeanExporter.getServer(); // 比较 mBeanServerFromBean 是否与平台 MBeanServer 相同 System.out.printf("来自于 MBeanExporter Bean 的 MBeanServer 是否相当于 ManagementFactory.getPlatformMBeanServer() : %b\n", mBeanServerFromBean == ManagementFactory.getPlatformMBeanServer()); System.out.printf("来自于 MBeanExporter Bean 的 MBeanServer 是否相当于 ManagementFactory.createMBeanServer() : %b\n", mBeanServerFromBean == mBeanServerFromCreate); System.out.println("按任意键结束..."); System.in.read(); // 关闭应用上下文 context.close(); }