[英]what is the purpose of @Component in OSGI factory implementations?
I am trying to implement servicefactory using apache felix scr annotations. 我正在尝试使用apache felix scr注释来实现servicefactory。
@Component
@Service(serviceFactory = true)
@Properties(value = { @Property(name = "className", value = "interface1") })
public class Tinterfaceimpl1 implements Tinterface {
@Override
public void consumeService() {
System.out.println("tinterfaceimpl1");
}
}
Above code is working fine. 上面的代码工作正常。 But what is the purpose of @Component?
但是@Component的目的是什么? Because i am trying to expose it as a service instead of both Component & Service.
因为我试图将其公开为服务,而不是组件和服务。 If i remove the @Component state is unsatisfied.
如果我删除@Component,则状态不满意。 IS it really mandatory for a factory to use both component and service?
工厂同时使用组件和服务真的是强制性的吗? pom.xml
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TinterfaceImpl</groupId>
<artifactId>TinterfaceImpl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.3.5</version>
<!-- <configuration>
<instructions>
<Import-Package>com.java.serviceeg.tinterface.Tinterface</Import-Package>
</instructions>
</configuration> -->
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.14.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Felix SCR annotations -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.9.6</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>Tinterface</groupId>
<artifactId>Tinterface</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>bundle</type>
</dependency>
</dependencies>
<packaging>bundle</packaging>
</project>
Yes this is mandatory. 是的,这是强制性的。 It declares your class as a Component according to the Declarative Services specifcation.
它根据声明式服务规范将您的类声明为Component。 Without the
@Component
annotation, it is merely some class hanging around in your bundle. 没有
@Component
批注,它只是捆绑包中的某个类。
Components may also be published as services, as in this example. 组件也可以作为服务发布,如本例。 But components do not have to be services -- instead they might expose some kind of external interface like a server socket or a GUI.
但是组件不必一定是服务,而是可以公开某种外部接口,例如服务器套接字或GUI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.