此页面尚未翻译成中文,以下为英文原文。
JMX support
此内容尚不支持你的语言。
Every Config object created by OWNER is also a Dynamic MBean: you can register it on an
MBeanServer and inspect or modify your configuration at runtime with any JMX client, such as JConsole or
VisualVM.
There is nothing to enable: just register the config instance on the MBean server of your choice.
public interface MyConfig extends Mutable, Reloadable { @Key("server.port.number") @DefaultValue("80") int port();
@Key("server.host.name") @DefaultValue("localhost") String hostname();}
MyConfig cfg = ConfigFactory.create(MyConfig.class);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();mbs.registerMBean(cfg, new ObjectName("org.aeonbits.owner:type=configuration,name=MyConfig"));What the MBean exposes
Section titled “What the MBean exposes”- Attributes: one per property, named after the property key (for instance
server.port.number). Attributes are exposed as strings and are both readable and writable: setting an attribute updates the configuration exactly like asetProperty()call on a Mutable config. - Operations:
getProperty(key)— gets the value for a property;setProperty(key, value)— sets the value for a property;reload()— reloads the configuration, like areload()call on a Reloadable config.
Changes performed through JMX act on the live configuration object: the next call to a config method will return the updated value. Combined with the event support, this lets your application react immediately to changes applied from a JMX console:
cfg.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { System.out.printf("property %s changed from %s to %s%n", evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); }});A runnable demo is available in JMXExample on GitHub: launch it, attach JConsole to the process, and play with
the attributes and operations of the org.aeonbits.owner:type=configuration,name=MyConfig MBean.
Same instance, multiple names
The same config instance can be registered on the MBean server under multiple object names; all the registrations act on the same underlying configuration.