Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Config same annotation bean in multiple config classes

 
Rj Ewing
Ranch Hand
Posts: 118
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to switch to java config from xml.

We have a core library, and then implementations that use the core library. We also have webapp and cli in each implementation. I am trying to modularize the config. We do use component scanning for certain packages. I am running into a circular dependency issue in the config classes. I need to inject the same @Component into beans created in multiple java config classes. My configs are as follows:







What would be the best way to solve this?

1 option would be to not use component scanning. Others?
 
Rj Ewing
Ranch Hand
Posts: 118
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, this is in the wrong forum. Can someone please move this to the Spring forum?
 
Rj Ewing
Ranch Hand
Posts: 118
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So after a bit more digging, this has to do with me trying to override a bean in the java config.





I am trying to override the SettingsBean, however CoreAppConfig uses SettingsBean to create MyBean. I think this is why I am getting a BeanCurrentlyInCreationException error. Any ideas how to resolve this?
 
Ankit Garg
Sheriff
Posts: 9597
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't override beans like that. Ideally you should make the parameter to SettingsBean dynamic like ${PROD_NAME} or something similar. You can then specify this value using environment variable...
 
Rj Ewing
Ranch Hand
Posts: 118
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, I ended up putting the SettingsBean in a separate config, then using @PropertySource(), i retrieve the param for SettingsBean
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!