将Java应用程序侦听从0.0.0.0更改为127.0.0.1-JMX

时间:2019-04-02 09:13:18

标签: java spring spring-boot jmx

为什么JMX监听0.0.0.0?可以将听音更改为仅127.0.0.1吗?

我在JMX文档中搜索了有关监听0.0.0.0的任何信息,但没有发现任何信息。

当我运行我的应用并签入cmd netstat时,它会打印  TCP 0.0.0.0:1099 0.0.0.0:0 LISTENING [java.exe]

我注册Bean像:

    @Bean
    public ConnectorServerFactoryBean serverConnector() throws MalformedObjectNameException {
        ConnectorServerFactoryBean factoryBean=new ConnectorServerFactoryBean();
        factoryBean.setServiceUrl("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/appname");
        factoryBean.setThreaded(true);
        return factoryBean;
    }

    @Bean
    public RmiRegistryFactoryBean registry() {
        RmiRegistryFactoryBean factoryBean=new RmiRegistryFactoryBean();
        factoryBean.setPort(1099);
        factoryBean.setAlwaysCreate(true);
        return factoryBean;
    }

    @Bean
    public MBeanServerConnection clientConnection() throws IOException {
        MBeanServerConnectionFactoryBean factoryBean = new MBeanServerConnectionFactoryBean();
        factoryBean.setServiceUrl("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/appname");
        factoryBean.afterPropertiesSet();
        return factoryBean.getObject();
    }

任何想法如何将其更改为仅127.0.0.1? 我使用的是Spring Boot 1.4.1.RELEASE

1 个答案:

答案 0 :(得分:0)

您可以使用Java选项-Djava.rmi.server.hostname=127.0.0.1仅在127.0.0.1上监听