问题
maybe I am plain stupid, but how do I set a list in a property value? For example with the felix scr annotations, a servlet looked somewhat like this
@Component(metatype = false)
@SlingServlet(
methods = { "GET", "POST" },
resourceTypes = "sling/servlet/default",
selectors = { "size" },
paths = { "/some/stupid/path/.*" }
with the new osgi service annotations
@Component(service = Servlet.class,
property = {
"sling.servlet.methods=GET",
"sling.servlet.methods=POST",
"sling.servlet.resourceTypes=sling/servlet/default",
"sling.servlet.selectors=size",
"sling.servlet.paths=/some/stupid/path.*" })
How can I set the servlet.methods as a list? Admittedly in this example it is not much of a problem, but I have a servlet that activates on a lot of selectors, and I really do not want to have 20 lines of "sling.servlet.selectors=..."
回答1:
From the javadoc: To specify a property with multiple values, use multiple name, value pairs. For example, "foo=bar", "foo=baz".
So what you have should work in that the value of sling.servlet.methods
will be an array [GET,POST]
Support for the future DS 1.4 spec should make this easier by allowing annotations to set property values. See 5.10 in RFC 222.
来源:https://stackoverflow.com/questions/41243873/osgi-r6-service-component-annotations-property-list