Spring项目中获取Java命令的参数

spring-property.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans     
http://www.springframework.org/schema/beans/spring-beans.xsd     
http://www.springframework.org/schema/context     
http://www.springframework.org/schema/context/spring-context.xsd">  
  <!-- ${url} -->  
  <context:property-placeholder location="classpath:application.properties"/>  

  <!-- 使用Spring自带的占位符替换功能 -->  
  <!-- nohup java -Ddubbo.service.server.port=20883 -jar falsework-provider-app.jar > 2018-10-27-falsework-provider-app.log & -->  
  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <!-- 系统-D参数覆盖 -->  
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>  
    <!-- 指定properties配置所在位置 -->  
    <property name="location" value="classpath:application.properties"/> 
  </bean> 
</beans>

指定Dubbo协议的端口

1
<dubbo:protocol name="dubbo" port="${dubbo.service.server.port}"/>

示例

1
nohup java -Ddubbo.service.server.port=20880 -jar falsework-provider-app.jar > 2018-10-27-falsework-provider-app.log &

参考文档

dubbo常见问题–使用多个进程启动服务,端口冲突怎么办?