Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13582

Camel main - Configuration class should support automatic autowire by type

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0-M3, 3.0.0
    • Component/s: camel-core
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      In such a configuration class

      public class MyConfiguration {
      
          @BindToRegistry
          public ClientConfiguration myClientConfig() {
              ClientConfiguration cc = new ClientConfiguration();
              cc.setMaxConnections(5);
              return cc;
          }
      
          @BindToRegistry
          public MyBean myBean(@PropertyInject("hi") String hi, @PropertyInject("bye") String bye) {
              // this will create an instance of this bean with the name of the method (eg myBean)
              return new MyBean(hi, bye);
          }
      
          @BindToRegistry
          public AmazonS3 myAmazon(@BeanInject("myClientConfig") ClientConfiguration config) {
              return AmazonS3Client.builder().withRegion("US-EAST-1").withClientConfiguration(config).build();
          }
      
          public void configure() {
              // this method is optional and can be removed if no additional configuration is needed.
          }
      
      }
      

      We could detect that the myAmazon method has a parameter of type ClientConfiguration which we can attempt to lookup as singleton bean. Then you can do

          @BindToRegistry
          public AmazonS3 myAmazon(ClientConfiguration config) 
      

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              davsclaus Claus Ibsen
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: