Ordering issue with Instantiation of Spring XML and Java Configuration Beans Related to Properties -


i have ordering problem. @bean runs after xml bean. need reversed, because @bean establishes properties xml bean needs. appears @importresource annotations processed before @configuration, @bean annotations processed.

i have configuration class bootstrapped class annotated @contextconfiguration. first annotated such:

  • @configuration
  • @import(propertyconfiguration.class)
  • @importresource(consts.xml_based_config_file)

propertyconfiguration.class includes @bean definition uses propertysource ( not annotation ) pull in properties use xml bean defined in consts.xml_based_config_file.

the @importresource routine reference existing xml based bean def file both java , xml beans interoperate.

everything runs great except ordering issue.

i’ve tried bringing in properties using @properysource – best can tell annotation not support running custom bean property source jdbc database. i’ve established @propertysource runs before @importresource have resolved ordering. i’ve tried @lazy(false) on @bean method – doesn’t help.

the next thing bootstrapping @configuration xml file – however, i’m thinking not matter.

any appreciated. thanks.

@importresource annotations indeed processed before @configuration, @bean annotations processed. did not find way reverse order. imported resource xml file based bean definition referencing spring properties, properties not yet set before bean created , results in error. implies, cannot implement @configuration, @beans along side xml beans when set properties within @bean method , expect properties set before being referenced xml bean.

in case, @bean establishing properties jdbc source.

to around this, had convert each xml bean referencing properties @beans.

hope helps


Comments