Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-3332

SCR annotations @Activate @Deactivate @Modified in outer classes also affect nested classes, annotations in nested classes are ignored

    XMLWordPrintableJSON

Details

    Description

      When maven-scr-plugin processes components that are implemented as nested classes, SCR annotations @Activate @Deactivate @Modified in these nested classes are ignored. Annotations in the outer class are used instead:

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

      @Component
      public class Outer {

      @Activate
      private void activateOuter() {
      }

      @Component
      public static class Nested1 {
      }

      @Component
      public static class Nested2 {

      @Activate
      private void activateNested2() {
      }

      }

      }

      results in this component description:

      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
      <scr:component enabled="true" name="Outer" activate="activateOuter">
      <implementation class="Outer"/>
      <property name="service.pid" value="Outer"/>
      </scr:component>
      <scr:component enabled="true" name="Outer$Nested1" activate="activateOuter">
      <implementation class="Outer$Nested1"/>
      <property name="service.pid" value="Outer$Nested1"/>
      </scr:component>
      <scr:component enabled="true" name="Outer$Nested2" activate="activateOuter">
      <implementation class="Outer$Nested2"/>
      <property name="service.pid" value="Outer$Nested2"/>
      </scr:component>
      </components>

      All components have an activate="activateOuter" attribute. Similar problems occur if the outer class is not a component or does not have an @Activate annotation:

      public class Outer {

      @Component
      public static class Nested {

      @Activate
      private void activateNested() {
      }

      }

      }

      Here the activate attribute is missing:

      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
      <scr:component enabled="true" name="Outer$Nested">
      <implementation class="Outer$Nested"/>
      <property name="service.pid" value="Outer$Nested"/>
      </scr:component>
      </components>

      Attachments

        Activity

          People

            cziegeler Carsten Ziegeler
            daniel-faber Daniel Faber
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: