java - SpringBoot get environment variables for @Configuration class -


i'm struggling following problem:

in springboot project want initialize datasource myself. inside method want work environment variables read yml file.

@configuration public class datasourceconfig {     @bean     public jdbcdatasource createmaindatasource() {         // init datasource , read environment variables     } } 

application.yml:

spring:   datasource:     url: jdbc:mysql://localhost:3306/xxx     driverclassname: com.mysql.jdbc.driver 

then defined class @configuration obtain environment variables.

@configuration @configurationproperties(prefix="spring.datasource") public class propertiesconfig {      private string url;      private string driverclassname; } 

but have problem class datasourceconfig being initialized before propertiesconfig leading problem can't use environment variables.

can of me that?

to create datasource need propertiesconfig, inject bean:

@configuration public class datasourceconfig {      @autowired     private propertiesconfig propertiesconfig;      @bean     public jdbcdatasource createmaindatasource() {         // init datasource , read environment variables     } } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -