Skip to content

Add support for Bean Overriding in transactionoutbox-spring #693

@ironhide0396

Description

@ironhide0396

[Copied over from #681]

It is quite a normal use case for developers to have a baseBean in the production files and have an overridden one in the test files. The bean in the test file is marked with @Primary so that it takes precedence when being invoked from tests.

Now, in case of using transactionoutbox-spring, the following method

@Override
public String getName(Class<?> clazz) {
    String[] beanNames = applicationContext.getBeanNamesForType(clazz);
    if (beanNames.length > 1) {
      throw new IllegalArgumentException(
          "Type "
              + clazz.getName()
              + " exists under multiple names in the context: "
              + Arrays.toString(beanNames)
              + ". Use a unique type.");
    }
    if (beanNames.length == 0) {
      throw new IllegalArgumentException(
          "Type " + clazz.getName() + " not available in the context");
    }
    return beanNames[0];
}

throws errors when there are more than 2 beans for the same class.

Action Items :

  1. Modify above mentioned class to return the bean definition for a class which has a higher precedence (marked using @Primary)
  2. Add tests for above corner case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions