Announcement Announcement Module
Collapse
No announcement yet.
Equivalent of abstract="true" and parent="beanConfig" in Java Config? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Equivalent of abstract="true" and parent="beanConfig" in Java Config?

    Hi,

    I'm using Spring 3, what is the best way to obtain the equivalent behavior of abstract="true" and parent="beanConfig" in Java Config?

    Currently I use:

    Code:
    @Configuration
    public A extends ParentConfig {
    
     @Bean
     public Transport myTransport() {
      Transport t = transport();
       ... do some specific setup
       return t;
     }
    }
    
    @Configuration
    public ParentConfig {
     public Transport transport() {
      ... doing some default setup
      return new Transport();
     }
    }
    Ideally I'd like the parent config to have a template method that returns a bean and delegate specific config through invocatino of an abstract method (so the parent config would be an abstract class)

    In general, I need guidelines on how to achieve this,
    Thanks,
    Guillaume Jeudy

  • #2
    Hi Guillaume,

    take a look over this thread. It may give you an idea about how to use inheritance.

    Best,
    Carlos

    Comment


    • #3
      There isn't... You cannot create a bean to be abstract or parent (search the forum I answered a couple of these questions).

      Simply create a method which constructs your object, and call that from the @Bean annotated method.

      Code:
      public class MyConfiguration {
      
        private MyObject basicObject() {
          // do basic construction here
        }
      
        @Bean
        public MyObject bean1() {
          MyObject bean1 = basicObject();
          // do additional config here
        }
      
        @Bean
        public MyObject bean2() {
          MyObject bean2 = basicObject();
          // do additional config here
        }
      
      }

      Comment

      Working...
      X