Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java bootstrap.properties中的替换和注入不';行不通_Java_Open Liberty_Microprofile - Fatal编程技术网

Java bootstrap.properties中的替换和注入不';行不通

Java bootstrap.properties中的替换和注入不';行不通,java,open-liberty,microprofile,Java,Open Liberty,Microprofile,在pom中,我定义了一些与配置文件相关的属性 <profiles> <profile> <!-- localhost --> <id>LOCAL</id> <activation> <activeByDefault>true</activeByDefault>

在pom中,我定义了一些与配置文件相关的属性

<profiles>
        <profile>
            <!-- localhost -->
            <id>LOCAL</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <ADServiceUID>uid-c0a84980-33489f60-15ca1a4bd66--7ff7</ADServiceUID>
                <LDAPServiceUID>uid-c0a84980-4e8eaad4-15d55058ca2--7efe</LDAPServiceUID> 
                <WLAN_VPNServiceUID>uid-c0a84980-4e8eaad4-15d55058ca2--7ef6</WLAN_VPNServiceUID>
                <MailboxServiceUID>uid-c0a84980-33489f60-15ca1a4bd66--7f1b</MailboxServiceUID>
                <BiolAuthServiceUID>uid-7f001-5698ac8b-15e9a06bf32--7fbf</BiolAuthServiceUID>
                <HestAuthServiceUID>uid-c0a84980--166b2589-1646afda4f8--7ff0</HestAuthServiceUID>
                <ItetAuthServiceUID>uid-7f001-5698ac8b-15e9a06bf32--7fbd</ItetAuthServiceUID>
                <LdapsProxyServiceUID>uid-c0a84980--562f2389-15f29329a10--7126</LdapsProxyServiceUID>
                <OpenDirServiceUID>uid-c0a8f781--4baed631-15ec752b318--7d1a</OpenDirServiceUID>
                <PhysicMailServiceUID>uid-c0a84980-33489f60-15ca1a4bd66--7fed</PhysicMailServiceUID>
                <ADUserPrivGrpServiceUID>uid-ac10be8b-172512a1-15f483b1c37--7fc9</ADUserPrivGrpServiceUID>
            </properties>
        </profile>
    </profiles>
我运行
mvn clean install
,target/classes下的bootstrap.properties设置了值

## UIDs of the IT-Services (set in pom)
it-service.ad = uid-c0a84980-33489f60-15ca1a4bd66--7ff7
it-service.ldap = uid-c0a84980-4e8eaad4-15d55058ca2--7efe
it-service.wlan_vpn = uid-c0a84980-4e8eaad4-15d55058ca2--7ef6
it-service.mailbox = uid-c0a84980-33489f60-15ca1a4bd66--7f1b
it-service.biolauth = uid-7f001-5698ac8b-15e9a06bf32--7fbf
it-service.hestauth = uid-c0a84980--166b2589-1646afda4f8--7ff0
it-service.itetauth = uid-7f001-5698ac8b-15e9a06bf32--7fbd
it-service.ldaps_proxy = uid-c0a84980--562f2389-15f29329a10--7126
it-service.opendirectory = uid-c0a8f781--4baed631-15ec752b318--7d1a
it-service.physik_mail = uid-c0a84980-33489f60-15ca1a4bd66--7fed
it-service.ad_userprivategroup = uid-ac10be8b-172512a1-15f483b1c37--7fc9
而src/main/liberty/config下的同一个文件仍然具有占位符

此外,当我试图在应用程序中读取这些属性时,它们是null

@Inject
  @ConfigProperty( name = "it-service.ad" )
  private Provider<String> itServiceADUID;

  @Inject
  @ConfigProperty( name = "it-service.ldap" )
  private Provider<String> itServiceLdapUID;

  @Inject
  @ConfigProperty( name = "it-service.wlan_vpn" )
  private Provider<String> itServiceWlanVpnUID;

  @Inject
  @ConfigProperty( name = "it-service.mailbox" )
  private Provider<String> itServiceMailboxUID;
...

private void initITServiceUIDs()
  {
    this.itServiceUIDs = new HashMap<>();
    this.itServiceUIDs.put("AD", this.itServiceADUID.get());  <--- line 230
    this.itServiceUIDs.put("Ldap", this.itServiceLdapUID.get());
    this.itServiceUIDs.put("Mailbox", this.itServiceMailboxUID.get());
    this.itServiceUIDs.put("Wlan_Vpn", this.itServiceWlanVpnUID.get());
...
  }

我遗漏了什么或做错了什么?

Francesco,首先检查您正在注入config的类是否作为CDIBean正确启用(使用bean定义注释或存在有效的beans.xml)


第二,您从哪里调用
initITServiceUIDs
?如果您从构造函数调用它,那么字段还没有被注入。

Francesco,首先检查您正在注入config的类是否作为CDIBean正确启用(带有bean定义注释或存在有效的beans.xml)


第二,您从哪里调用
initITServiceUIDs
?如果您从构造函数调用它,那么字段将不会被注入。

您启用了什么功能集?@Scott Kurz:server.xml中的注意事项有:mpHealth-2.2、mpOpenAPI-1.1、mpConfig-1.4、mpRestClient-1.4、servlet-4.0、jaxrs-2.1、jsonp-1.1、jsonb-1.0、,cdi-2.0您启用了什么功能集?@Scott Kurz:server.xml中的注意事项有:mpHealth-2.2、mpOpenAPI-1.1、mpConfig-1.4、mpRestClient-1.4、servlet-4.0、jaxrs-2.1、jsonp-1.1、jsonb-1.0、cdi-2.0该类带有RequestScope注释。您是对的。我从构造函数中调用它。现在,我用PostConstruct注释了该方法,并且值不再为null。但问题是,这些值没有被pom中定义的值替换,这一问题仍然存在。HashMap包含${ADServiceUID}、${LDAPServiceUID},…。不清楚如何将属性值从Maven/POM传播到boostrap.properties。一种方便的以Maven为中心的方法,尤其对概要文件有用,就是使用POM属性,如
liberty.bootstrap.xyz
。有关更多详细信息,请参阅。您可以定义POM属性:
propValue
,这将导致在boostrap.properties文件中生成属性:
ADServiceUID=propValue
。该类带有requestScope注释。您是对的。我从构造函数中调用它。现在,我用PostConstruct注释了该方法,并且值不再为null。但问题是,这些值没有被pom中定义的值替换,这一问题仍然存在。HashMap包含${ADServiceUID}、${LDAPServiceUID},…。不清楚如何将属性值从Maven/POM传播到boostrap.properties。一种方便的以Maven为中心的方法,尤其对概要文件有用,就是使用POM属性,如
liberty.bootstrap.xyz
。有关更多详细信息,请参阅。您可以定义POM属性:
propValue
,这将导致在boostrap.properties文件中生成属性:
ADServiceUID=propValue
@Inject
  @ConfigProperty( name = "it-service.ad" )
  private Provider<String> itServiceADUID;

  @Inject
  @ConfigProperty( name = "it-service.ldap" )
  private Provider<String> itServiceLdapUID;

  @Inject
  @ConfigProperty( name = "it-service.wlan_vpn" )
  private Provider<String> itServiceWlanVpnUID;

  @Inject
  @ConfigProperty( name = "it-service.mailbox" )
  private Provider<String> itServiceMailboxUID;
...

private void initITServiceUIDs()
  {
    this.itServiceUIDs = new HashMap<>();
    this.itServiceUIDs.put("AD", this.itServiceADUID.get());  <--- line 230
    this.itServiceUIDs.put("Ldap", this.itServiceLdapUID.get());
    this.itServiceUIDs.put("Mailbox", this.itServiceMailboxUID.get());
    this.itServiceUIDs.put("Wlan_Vpn", this.itServiceWlanVpnUID.get());
...
  }
Caused by: java.lang.NullPointerException
[INFO]  at ch.ethz.id.sws.iamws.dirxwsclient.service.ServiceClient.initITServiceUIDs(ServiceClient.java:230)