ich eine Komponente MyComponent haben, die AConfiguration und BConfiguration zugreifen muss:Mehrere Konfigurationen (@ Meta.OCD-Schnittstelle) in der gleichen Komponente
my.MyComponent:
@Component(
configurationPid = "[my.AConfiguration,my.BConfiguration]"
)
public class MyComponent {
@Activate
@Modified
protected void activate(Map<String, Object> properties) {
_aConfiguration = ConfigurableUtil
.createConfigurable(AConfiguration.class, properties);
_bConfiguration = ConfigurableUtil
.createConfigurable(BConfiguration.class, properties);
}
public void hello() {
System.out.println("A:" + _sConfiguration.valueA());
System.out.println("B:" + _sConfiguration.valueB());
}
}
my.AConfiguration:
@Meta.OCD(
id = "my.AConfiguration"
)
public interface AConfiguration {
@Meta.AD(deflt = "6")
public long valueA();
}
my.BConfiguration:
@Meta.OCD(
id = "my.BConfiguration"
)
public interface BConfiguration {
@Meta.AD(deflt = "6")
public long valueB();
}
Problem: Die Konfiguration von valueA und valueB auf 7
mit der Liferay-Konfigurationsoberfläche hat keine Wirkung, MyComponent.hello()
sieht immer noch den Standardwert 6
.
Was mache ich falsch?
Was ist der richtige Weg, um meine Komponente dazu zu bringen, Konfigurationsinformationen von mehreren Konfigurationsschnittstellen zu verwenden?
Anwendungsfall: Meine Komponente verarbeitet einige Geschäftsvorgänge und speichert Ergebnisse auf einem Remote-Server. Es gibt eine Konfigurationsschnittstelle mit den Geschäftsverarbeitungseinstellungen und eine Konfigurationsschnittstelle mit der URL zum Remoteserver.
Oh, interessant! Die Verwendung mehrerer Konfigurationen ist also OK, wenn Sie diese Syntax verwenden? Vielen Dank! –
Ja. Dies ist die Standard-Java-Syntax zum Erstellen eines String-Array-Werts in einem Anmerkungsattribut. Leider erzeugt Java Mehrdeutigkeit, da es ermöglicht, dass ein Array mit einem einzelnen Eintrag ohne die geschweiften Klammern erstellt wird. Das heißt, 'configurationPid =" foo "' ist äquivalent zu 'configurationPid = {" foo "}' –