通过spring设置java系统属性

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/buyaore_wo/article/details/8053095

在做RMI的时候需要如遇到rmi所在服务是多网卡时,需要对系统属性java.rmi.server.hostname进行设置 ,以前我们会扩展spring的listener

public class SpringContextLoaderListener extends ContextLoaderListener {

	@Override
	public void contextInitialized(ServletContextEvent event) {
		//初始化之前在设置java.rmi.server.hostname
                System.setProperty("java.rmi.server.hostname", "ip");
		super.contextInitialized(event);
	}

}

虽然这样没问题, 但是spring为我们提供了更简单快捷的方式,只需要配置就行了


	<bean
		class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
		<property name="targetObject" value="#{@systemProperties}" />
		<property name="targetMethod" value="putAll" />
		<property name="arguments">
			<props>
				<prop key="java.rmi.server.hostname">${java.rmi.server.hostname}</prop>
			</props>
		</property>
	</bean>


猜你喜欢

转载自blog.csdn.net/buyaore_wo/article/details/8053095