Can I simplify spring configuration file beans by combining the annotations onto one method?

34 Views Asked by At

I m making a @Configuration class that is to just provide the names of topics and queues I want to publish/subscribe to using JMS. The config file looks something like the following but repeated 10+ times.

@Value("myTopic")
private String myTopic;
@Bean("myTopic")
public String getMyTopic() { return this.myTopic; }

I was wondering if I could simplify it to the following. Whether it is best practice, allowed etc?

@Bean("myTopic")
public String getMyTopic(@Value("myTopic") final String myTopic) { return myTopic; }

I did not put the topics and queues inside application.properties, because this configuration class is being used by two different projects. If the values are put into application.properties, it would require both projects to include those values inside their application.properties, but I dont have access to change those

0

There are 0 best solutions below