我的10_channel_jpos.xml中有一个频道配置,我希望能够从属性文件中获取ip和端口并从我的代码中设置它,因为这些值可能会改变
<channel-adaptor
name="mybank-channel-adaptor-pri"
class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
<channel name="ServerA-Channel" class="org.jpos.iso.channel.NACChannel"
logger="Q2" realm="ServerA-Channel"
packager="org.jpos.iso.packager.ISO87APackager">
<property name="timeout" value="3600000"/>
<property name="host" value="${myBankHostPrimary}"/>
<property name="port" value="${myBankPortPrimary}"/>
<property name="packager-config" value="cfg/base1.xml" />
<property name="keep-alive" value="true" />
</channel>
<in>from-mybank-pri</in>
<out>to-mybank-pri</out>
<reconnect-delay>5000</reconnect-delay>
</channel-adaptor>
和属性文件
###### GENERAL INFO
NODE = NODE001
###### Environment
env=DEV
###### Ports we listens to
server_listen_port = 9999
###### Target host information
myBankHostPrimary=127.0.0.1
myBankPortPrimary=8001
###### DEBUG STUFF
debugParticipant=true
和主要课程
public static void main (String[] args) throws Exception {
ChannelAdaptor channel= (ChannelAdaptor) NameRegistrar.get ("mybank-channel-adaptor-pri");
channel.setHost = "127.0.0.1"; // Value gotten from the property file
System.out.println(channel.getHost());
}
请问如何设置属性主机值和端口值?
我的文件夹结构是
bin
.....bsh
.....q2.bat
.....start.bat
.....stop
build
......META-INF
.......org
.......jpos
........config
......Q2-decorator.property
.....cfg
.....config.properties (my property file)
答案 0 :(得分:1)
除了之前的答案,您还可以将configuration-factory
属性添加到<channel>
元素并创建自己的ConfigurationFactory。然后,您的实现可以从任何地方选择属性值。
SysconfigConfigurationFactory从数据库的sysconfig
表中选择属性。您可以将其用作创建自己的自定义解决方案的灵感。
答案 1 :(得分:0)
您需要执行以下步骤:
在您的代码中,您可以执行以下操作:
channel.stop();
channel.setPort(port);
channel.setHost(host);
channel.start();
答案 2 :(得分:0)
如果要在启动Q2之前更改属性,则需要使用decorator。这包含在标准jpos中。
作为that page states,您需要在项目中创建一个资源,该资源位于类路径的'META-INF / org / jpos / config / Q2-decorator.properties'中(而不是文件系统!)。
内容:
config-decorator-class=org.jpos.q2.freemarker.FreemarkerDecorationProvider (1)
config-files=cfg/config.properties (2)
cfg / properties中的哪个属性文件。
您还必须向org.jpos.ee:jposee-freemarker-decorator添加依赖项。我不知道你是否正在建造maven或gradle。