spring - Can I programatically add a qualifier to a bean? -



spring - Can I programatically add a qualifier to a bean? -

i registering transaction managers in code, utilize annotation based configuration don't know until runtime how many info sources (and hence transaction managers) there be, have programatically register these, follows:

private final void registertransactionmanagerbean(final datasource datasource, configurableapplicationcontext context) {

string transactionmanagername = this.getname() + "-transactionmanager"; context.getbeanfactory().registersingleton(transactionmanagername, new datasourcetransactionmanager(datasource)); log.info("registering transaction manager under name : " + transactionmanagername);

}

assuming this.getname() returned 'mydb', expected able qualify transacton manager this:

@transactional("mydb-transactionmanager")

what i've realised value of annotation refers qualifier , not name. did quick test declaring bean below , works:

@bean @qualifier("mydb-transactionmanager") public platformtransactionmanager test() { homecoming new datasourcetransactionmanager(new embeddeddatabasebuilder().build()); }

my question is, there way can programatically add together qualifier when registering bean?

much appreciated.

update

i've worked out, i'm falling foul of problem (in beanfactoryannotationutils:isqualifiermatch):

catch (nosuchbeandefinitionexception ex) { // ignore - can't compare qualifiers manually registered singleton object }

i manually registering transaction manager bean presume why i'm stuck. i'm not sure options gives me apart not programatically register transaction managers runtime thing sadly.

i've worked out, i'm falling foul of problem:

catch (nosuchbeandefinitionexception ex) { // ignore - can't compare qualifiers manually registered singleton object }

i manually registering transaction manager bean presume why i'm stuck. i'm not sure options gives me apart not programatically register transaction managers runtime thing sadly.

raised jira issue - https://jira.spring.io/browse/spr-11915

spring spring-transactions

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -