Hi
I am using AnnotationConfigApplicationContext to register/scan my @Configuration annotated class. I have one bean annotated with @Bean annotation that needs some external values. Something like:
I know the values of username and password at the time of creating AnnotationConfigApplicationContext instance i.e. during:Code:@Bean public ConnectionFactory connectionFactory() { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUserName(------------------); connectionFactory.setPassword(------------------); // ------------- }
AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
Note 1: I am creating AnnotationConfigApplicationContext dynamically not on startup (i.e. not on spring init phase)
Note 2: I cannot use properties file because username and password are coming from some other source (from some database).
Note 3: I am creating multiple AnnotationConfigApplicationContext on the fly for multi users.
I read some where that Spring 3.1 has new feature - StandardEnvironment but I am not sure how to use it.
My question is how can I pass username and password to @Bean annotated method.
Thanks


Reply With Quote