在AEM中,选择哪个OSGI配置取决于您的运行模式。以下是一些常见的AEM运行模式以及相应的OSGI配置示例:
作者模式(Author mode):
config.author.xml
@Component
@Designate(ocd = AuthorConfig.class)
public class AuthorComponent {
@ObjectClassDefinition
public @interface AuthorConfig {
@AttributeDefinition(name = "Author Mode Config", description = "Author mode specific configuration")
String authorConfig() default "default value";
}
@Activate
protected void activate(AuthorConfig config) {
String authorConfigValue = config.authorConfig();
// 进行作者模式特定的操作
}
}
发布模式(Publish mode):
config.publish.xml
@Component
@Designate(ocd = PublishConfig.class)
public class PublishComponent {
@ObjectClassDefinition
public @interface PublishConfig {
@AttributeDefinition(name = "Publish Mode Config", description = "Publish mode specific configuration")
String publishConfig() default "default value";
}
@Activate
protected void activate(PublishConfig config) {
String publishConfigValue = config.publishConfig();
// 进行发布模式特定的操作
}
}
全局模式(Global mode):
config.xml
(此配置文件将应用于所有运行模式)@Component
@Designate(ocd = GlobalConfig.class)
public class GlobalComponent {
@ObjectClassDefinition
public @interface GlobalConfig {
@AttributeDefinition(name = "Global Config", description = "Global configuration")
String globalConfig() default "default value";
}
@Activate
protected void activate(GlobalConfig config) {
String globalConfigValue = config.globalConfig();
// 进行全局模式下的操作
}
}
请根据您的需要选择适当的运行模式,并相应地配置和编写代码。
下一篇:AEM运行模式的优先顺序