vendredi 29 août 2014

spring-boot external configuration entire class


Vote count:

0




Following these instructions here I want to have my MQConnection class properties to be loaded from the application.properties file.


The problem is that the properties are only loaded if I put a @Value("${attributename}") annotation on each and every property. I do not want to tag each and every property, I rather set the class prefix and let spring correlate and map my class properties to those found in application.properties.


My setup:




  • application.properties is on the classpath in src/main/resources

  • My @Configuration class also has @EnableConfigurationProperties

  • My MQConnection class has both @Component and @ConfigurationProperties(prefix="mq")



Configuration class:



@Configuration
@EnableAutoConfiguration
@EnableConfigurationProperties
@ComponentScan
public class Application implements CommandLineRunner {
...
}


MQConnection class:



@Component
@ConfigurationProperties(prefix="mq")
public class MQConnection{

@Value("${mq.hostname}") // will only work if @Value is here, don't want this
private String hostname;
private int port;
private String qmanager;
private String queue;
private String channel;
}


application.properties:



mq.hostname=localhost
mq.port=5120
mq.qmanager=MyQueueManager
mq.queue=MyQueue
mq.channel=MyChannel


asked 2 mins ago







spring-boot external configuration entire class

Aucun commentaire:

Enregistrer un commentaire