Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Java Config same annotation bean in multiple config classes

 
Ranch Hand
Posts: 120
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 120
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 120
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 120
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I've never won anything before. Not even a tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic