5

Suppose i have a Maven Project A and Project B, and project B i am adding it as as a jar in Project A when i try to run Project A it gives me the error "bean name "xyz" conflicts with existing, non-compatible bean definition of same name and class"

So anyone has solution to this to ignore the bean "xyz" of Project B and run only "xyz" bean of Project A or is there any annotation or something like that?

3
  • Having that situation is kind of a code-smell. Perhaps it is time to look into refactoring? Commented May 8, 2017 at 8:24
  • Using @Lazy on bean "xyz" of Project B could be an approach? Commented May 8, 2017 at 10:32
  • @NielsBechNielsen actually i have created maven project with jersey archetype so both project A and B contains same Jersey Configuration file,..its default created class. that's why. now can u suggest me something which can work? Commented May 8, 2017 at 12:39

3 Answers 3

1

Use the @Primary annotation on the bean defenition on the configuration class

@Bean(name = "beanOnA") @Primary public YourInterface yourBeanOnProjectA(){ return new YourClass("Bean on Project A"); } 

While autowiring the bean specify the bean name using qualifier annotation.

@Autowired @Qualifier("beanOnA") YourInterface yourInterface; 
Sign up to request clarification or add additional context in comments.

Comments

-1

You can use Qualifier annotation to achieve this.

@Qualifier("ProjectA") or @Qualifier("complete.package.ProjectA") 

1 Comment

This only helps if you are able to edit the code. What if it is external dependensies
-2

You can edit pom file for B to exclude the class file while packing enter link description here

Edit pom file A using shade plugin to exclude the class file from B, enter link description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.