在 OSGI class 编译中找不到符号 @Activate 错误

cannot find symbol @Activate Error in OSGI class compilation

我正在尝试编写一个 OSGI class,它应该填充 Felix 控制台中的配置对话框,我的服务实现如下所示。但是当我尝试 运行 mvn clean install -PautoInstallPackage 时出现以下错误。感谢您的帮助。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project osgiexample.core: Compilation failure

[ERROR] /E://osgiexample/core/src/main/java/osgiexample/core/serviceimpl/TestServiceImpl.java:[40,10] cannot find symbol

[ERROR] symbol: class Activate

[ERROR] location: class osgiexample.core.serviceimpl.TestServiceImpl

@Component(immediate=true, label="TEST Service", description="Hello There - This is a Service component", metatype=true)
@Service(value=TestService.class)

public class TestServiceImpl implements TestService {

@Property(value="http://testservice/myservice?wsdl")
static final String SERVICE_ENDPOINT_URL = "service.endpoint.url";

private String serviceEndpointUrl;

    @Override
    public String getData() {
        // TODO Auto-generated method stub
        return null;
    }

    @Activate
    public void activate(final Map<String, Object> props) {
    System.out.println("Calling Activate Method");
    this.serviceEndpointUrl = (String)props.get(SERVICE_ENDPOINT_URL);
    System.out.println("ServiceEndpointUrl:" + this.serviceEndpointUrl);
}
}

在下面添加 Activate 注释导入语句应该可以解决您的问题

import org.apache.felix.scr.annotations.Activate;