import org.osgi.framework.BundleContext; import org.osgi.service.component.annotations.Component; import org.osgi.service.debug.DebugOptions; @Component public class MyDebugComponent { private BundleContext bundleContext; public void setBundleContext(BundleContext bundleContext) { this.bundleContext = bundleContext; } public void activate() { DebugOptions debugOptions = bundleContext.getService(DebugOptions.class); debugOptions.setDebugEnabled(true); } public void deactivate() { DebugOptions debugOptions = bundleContext.getService(DebugOptions.class); debugOptions.setDebugEnabled(false); } } <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="MyDebugComponent"> <implementation class="com.example.MyDebugComponent" /> <reference name="bundleContext" interface="org.osgi.framework.BundleContext" /> </scr:component>


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