1. 程式人生 > >jmx 用 rmi 註冊 報錯 java.rmi.ConnectException: Connection refused to host

jmx 用 rmi 註冊 報錯 java.rmi.ConnectException: Connection refused to host

用rmi登錄檔時,rmi一直報這個錯誤 這是我的三個配置bean

*@Bean
	public ConnectorServerFactoryBean connectorServerFactoryBean() {
		
		 ConnectorServerFactoryBean connectorServerFactoryBean = new ConnectorServerFactoryBean();
		 connectorServerFactoryBean.setServiceUrl("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
		 return connectorServerFactoryBean;
	}
	//生成rmi登錄檔以供connectorServerFactoryBean註冊
	@Bean
	public RmiRegistryFactoryBean rmiRegistryFactoryBean() {
		RmiRegistryFactoryBean rmiRegistryFactoryBean=new RmiRegistryFactoryBean();
		rmiRegistryFactoryBean.setPort(9999);
	return rmiRegistryFactoryBean;
	}
	//客戶端訪問連線工廠
	@Bean
	public MBeanServerConnectionFactoryBean mBeanServerConnectionFactoryBean() throws Exception {
		
		MBeanServerConnectionFactoryBean connectorServerFactoryBean = new MBeanServerConnectionFactoryBean();
		 connectorServerFactoryBean.setServiceUrl("service:jmx:rmi://localhost/jndi/rmi://localhost:9999/jmxrmi");
		 return connectorServerFactoryBean;
	}

由於我用maven tomcat外掛,一個專案跑三個埠,所以這三個bean放在相同的專案裡了。 但是一開始我讓前兩個bean跑在一個專案裡,就一直報這個錯。 後來我試著讓這三個bean分別跑在不同的埠,就沒報這個錯了。