Friday, November 19, 2010

@Component (maven scr plugin)

If you are writing an abstract Felix OSGi component, make sure componentAbstract is true:
@Component(componentAbstract=true, ...)
//@Service  Abstract component can't be Service
public abstract class Foo ....

Also, if you want your component to be configurable through Felix Web Console (/system/console/components  shows Configure button, little wrench icon), set metatype to true

@Component(metatype=true, ...)
public class Foo ...

Available fields on Felix Web Console can be configured using @Property annotation:

@Property(cardinality=-1000, label="Hosts", description="a list of hosts", value={})
private static final String PROP_HOSTS = "my.hosts";
This (along with metatype=true) will create a form field on Felix Web Console that has maximum number of elements of 1000. If you put more than 1000 entries through the form, 1001th element and on will be truncated.

The document,, says that cardinality=Integer.MIN_INT, but it does not work if you specify a variable there. See, .
Also, cardinality=-2147483648  won't work. Probably because it's too large. I get NumberFormatException.

To set the type of the property, use longValue, doubleValue...etc instead of value={}.

No comments:

Post a Comment