Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Bean Overriding in transactionoutbox-spring #693

Open
ironhide0396 opened this issue Aug 21, 2024 · 0 comments
Open

Add support for Bean Overriding in transactionoutbox-spring #693

ironhide0396 opened this issue Aug 21, 2024 · 0 comments

Comments

@ironhide0396
Copy link

[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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant