title: Java enum as spring component - Spring allows this but does not inject members that are declared in the enum
body: <p>I have a question on the behavior when making a java enum as a spring managed component with an <code>@Component</code> annotation. I see that spring allows this (<code>@Component</code> after all has <code>@Target(value=TYPE)</code>) but when i try to inject an enum member with <code>@Autowired</code> it does not get injected. Below is sample code snippet for our purpose (<code>ObjectMapper</code> does not get injected below),</p>
  <pre><code>@Component
  public enum AssetTypeEnum {
  
      SWITCH {
          @Override
          public AssetDataCollectionRequest getDataCollectionRequestObjectFromJsonString(String jsonString) throws JsonMappingException, JsonProcessingException {
              return objectMapper.readValue(jsonString, SwitchAssetDataCollectionRequest.class);
          }
      }, GIGE {
          @Override
          public AssetDataCollectionRequest getDataCollectionRequestObjectFromJsonString(String jsonString) throws JsonMappingException, JsonProcessingException {
              return objectMapper.readValue(jsonString, GigePortAssetCollectionRequest.class);
          }
      }, NAMESERVER {
          @Override
          public AssetDataCollectionRequest getDataCollectionRequestObjectFromJsonString(String jsonString) throws JsonMappingException, JsonProcessingException {
              return objectMapper.readValue(jsonString, AssetDataCollectionRequest.class);
          }
      };
  
      @Autowired
      ObjectMapper objectMapper;
      
      public abstract AssetDataCollectionRequest getDataCollectionRequestObjectFromJsonString(String jsonString) throws JsonMappingException, JsonProcessingException;// {
      //  return objectMapper.readValue(jsonString, AssetDataCollectionRequest.class);
      //}
      
      public AssetDataCollectionResponse getDataCollectionResponeObjectFromJsonString(String jsonString) throws JsonMappingException, JsonProcessingException {
          return objectMapper.readValue(jsonString, AssetDataCollectionResponse.class);
      }
  </code></pre>
  <p>Also in the above if i un-comment the commented lines above &amp; change the method from an abstract method, i get below weird error on app start up,</p>
  <pre><code>rest-sample-service - [WARN ] 03:57:49.385 [main] org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext   - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'assetTypeEnum' defined in file [/BOOT-INF/classes/com/**/**/sampleservice/common/AssetTypeEnum.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
  rest-sample-service - [INFO ] 03:57:49.574 [main] org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener   - 
  
  Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  rest-sample-service - [ERROR] 03:57:50.776 [main] org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter   - 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Parameter 0 of constructor in com.**.**.sampleservice.common.AssetTypeEnum required a bean of type 'java.lang.String' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'java.lang.String' in your configuration.
  </code></pre>
  <p>Anyone knows whats going on here?</p>
  <p>Thanks</p>