import org.apache.felix.scr.annotations.*; @Component @Service public class HelloWorldComponent { @Property(value = "Hello, World!") private static final String MESSAGE = "message"; @Reference private MyService myService; @Activate protected void activate() { System.out.println(myService.getMessage()); } } <?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="HelloWorldComponent"> <implementation class="com.example.HelloWorldComponent"/> <property name="message" type="String" value="Hello, World!"/> <reference name="myService" interface="com.example.MyService"/> <service> <provide interface="com.example.MyComponent"/> </service> </scr:component>


上一篇:
下一篇:
切换中文