Skip to content

Instantly share code, notes, and snippets.

@yupadhyay
Created February 14, 2016 18:10
Show Gist options
  • Save yupadhyay/c968410ec2e1974a56ae to your computer and use it in GitHub Desktop.
Save yupadhyay/c968410ec2e1974a56ae to your computer and use it in GitHub Desktop.
ConfigFactory in AEM
package wemblog.configfactory.test
@Component(configurationFactory = true, metatype = true)
@Service(value = MyCustomService.class)
public Class WemBlogFactory implements WemBlogService{
@Property(label="Test Property",name="test", description="This is test property example", value="test")
private String test;
@Activate
protected void activate(final Map<String, Object> config) {
this.test = PropertiesUtil.toString(config.get("test","some default");
}
}
Once you define a class with configfactory you can now create multiple configuration using this. For example for above use case you can now create multiple configurations like,
wemblog.configfactory.test.WemBlogFactory-Test1.xml
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
test="Test1">
wemblog.configfactory.test.WemBlogFactory-Test2.xml
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
test="Test2">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment