0

I want to create spring bean like:

 @Bean(name = {
        "foo",
        "bar",
        "${foobar}"
})

public FooBarBean getFooBarBean(

where ${foobar} name will be resolved from application.yml or from environment value on application init phase.

I am not sure @Bean annotation supports variables from context so code sample only as example as it would be if it is would be possible.

How can I set bean name from environment variable value (without usnig xml declaration)?

  • 3
    Why would you need this? – msfoster Mar 11 '19 at 10:59
  • Possible duplicate of [How to read values from properties file?](https://stackoverflow.com/questions/9259819/how-to-read-values-from-properties-file) – Mebin Joe Mar 11 '19 at 11:19
  • Why do we need this. We have a service endpoint for hessian, name of the hessian service bean exposed as a part of url so having bean declared as 'foo' will result to hessian endpoint like 'localhost/foo' for exposed hessian endpoint. We can't change this mechanism. Then we want to configure all possible bean names in yaml file. We don't want to use xml configurations at all. We want to have situation when we can see all possible bean names from yaml file either application.yaml or bootstrap.yaml. I think it would be possible to do to give the bean name from any pre-configured variable. – Dzmitry Prakapenka Mar 18 '19 at 08:59

0 Answers0