title: Using Proguard with a library has a @Service bean which should autowire
body: <p>I have a library Common.License which I am obfuscating with Proguard:  </p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;com.pyx4me&lt;/groupId&gt;
      &lt;artifactId&gt;proguard-maven-plugin&lt;/artifactId&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;proguard&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
      &lt;configuration&gt;
          &lt;obfuscate&gt;true&lt;/obfuscate&gt;
          &lt;options&gt;
              &lt;option&gt;-dontoptimize&lt;/option&gt;
              &lt;option&gt;-renamesourcefileattribute SourceFile&lt;/option&gt;
              &lt;option&gt;-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod&lt;/option&gt;
              &lt;option&gt;-keep public class * { public protected *;}&lt;/option&gt;
              &lt;option&gt;-keepclassmembernames class * {java.lang.Class class$(java.lang.String); java.lang.Class class$(java.lang.String, boolean);}&lt;/option&gt;
              &lt;option&gt;-keepclassmembernames class * {com.common.license.LicenseSessionStore licenseSessionStore; com.common.license.LicenseStore licenseStore;}&lt;/option&gt;
              &lt;option&gt;-keepclassmembers enum * {public static **[] values(); public static ** valueOf(java.lang.String);}&lt;/option&gt;
              &lt;option&gt;-keepclassmembers class * implements java.io.Serializable { static final long serialVersionUID; private static final java.io.ObjectStreamField[] serialPersistentFields; private void writeObject(java.io.ObjectOutputStream); private void readObject(java.io.ObjectInputStream); java.lang.Object writeReplace(); java.lang.Object readResolve();}&lt;/option&gt;
          &lt;/options&gt;
          &lt;libs&gt;
              &lt;lib&gt;${java.home}/lib/rt.jar&lt;/lib&gt;
              &lt;lib&gt;${java.home}/lib/jsse.jar&lt;/lib&gt;
          &lt;/libs&gt;
          &lt;addMavenDescriptor&gt;false&lt;/addMavenDescriptor&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>This library has a Spring bean annotated with @Service:</p>
  
  <pre><code>@Service
  public class LicenseServiceImpl implements LicenseService {
  
      @Autowired(required = false)
      LicenseSessionStore licenseSessionStore;
  
      @Autowired(required = false)
      LicenseStore licenseStore;
  
  ...
  
  }
  </code></pre>
  
  <p>I use this library in a web service Company.License where I want the LicenseService to autowire:</p>
  
  <pre><code>@Component
  public class BackgroundTasks {
  
      @Autowired
      ScheduledExecutorService scheduledExecutorService;
  
      @Autowired
      LicenseService licenseService;
  
  ...
  
  }
  </code></pre>
  
  <p>So Company.License has a dependency on Common.License.  If I obfuscate Common.License then <code>licenseService</code> will not autowire in <code>BackgroundTasks</code>.  The only way I could work around this was to define licenseService explicitly as a bean:</p>
  
  <pre><code>@Bean(name = "licenseService", autowire = Autowire.BY_NAME)
  public LicenseService getLicenseService() {
      if (licenseService == null) {
          licenseService = new LicenseServiceImpl();
      }
      return licenseService;
  }
  </code></pre>
  
  <p>I should not need to explicitly declare this as a bean like this as I have already annotated the class with <code>@Service</code> which should be enough to make the autowiring of <code>licenseService</code> in <code>BackgroundTasks</code> Spring-magically work.  But it doesn't!  </p>
  
  <p>What is Proguard specifically doing to make this not work?  Is there anything I can do in the configuration of Proguard to make it more Spring friendly?</p>
  
  <p>Grant</p>