spring - Java Config same annotation bean in multiple config classes -


i trying switch java config xml.

we have core library, , implementations use core library. have webapp , cli in each implementation. trying modularize config. use component scanning packages. running circular dependency issue in config classes. need inject same @component beans created in multiple java config classes. configs follows:

@configuration @componentscan(basepackages = {"my.components"}) @importresource({         "classpath:data-access-config.xml" }) @propertysource(value = "classpath:core.props", ignoreresourcenotfound = true) public class coreappconfig {     @autowired     environment env;      @autowired     componentbean bean;      @bean     public mybean mybean() {         return new mybean(bean);     } }   @configuration @import({coreappconfig.class}) @propertysource(value = "classpath:my-app.props") public class myappconfig {     @autowired     environment env;      @autowired     componentbean bean;      @bean     public mybean2 mybean2() {         return new mybean2(bean);     } }   @configuration @componentscan(basepackages = {"my.app.services"}) @import({myappconfig.class, coreappconfig.class}) public class mywebappconfig {     @autowired     environment env;      @autowired     myappconfig myappconfig;      @autowired     componentbean bean;      @bean     public myrestservice myrestservice() {         return new myrestservice(bean);     } } 

what best way solve this?

1 option not use component scanning. others?

edit:

the exception getting beancurrentlyincreationexception. if remove @import({coreappconfig.class}) or @autowired componentbean bean myappconfig, problem goes away.

edit 2:

so think circular dependency problem specific bean. can want other beans, specific bean giving me problems.

any tips on determining circular dependency?

edit 3:

okay i've figured out culprit. in coreappconfig create bean mypropsbean. in myappconfig, create same mypropsbean. hoping override coreappconfig.mypropsbean myappconfig.mypropsbean. think causing issue since both coreappconfig , myappconfig autowire componentbean. how can resolve this? whats best way override bean?

so solved moving creation of myappconfig bean separate config class. use @propertysources , create myappconfig bean passing in dynamic param.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -