Search code examples
osgiaemapache-felixosgi-bundle

cannot find symbol @Activate Error in OSGI class compilation


I am trying to write an OSGI class which should populate the configuration dialog in Felix console, my Service implementation as shown below. but when i try to run mvn clean install -PautoInstallPackage am getting the below error. any help is appreciated.

[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);
}
}

Solution

  • Add below Activate annotation import statement should resolve your issue

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