I'm trying to change Datasource setting from command Line. I have a application.properties with default setting. I would like to modify the parameters in the file from command Line, but when I pass Datasource arguments , I receive an error. I read on Externalized Configuration document :"Accessing Command Line Properties By default, SpringApplication converts any command line option arguments (that is, arguments starting with --, such as --server.port=9000) to a property and adds them to the Spring Environment. As mentioned previously, command line properties always take precedence over other property sources". I supposed that arguments overwrite the default setting into application.properties, but I'm missng some steps about that.
I've tried without spring.datasource.url or Placeholders in Properties. Below application.properties.
spring.datasource.url = jdbc:oracle:thin:@servername:port:DB11G
#spring.datasource.url = ${spring.datasource.url}
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
spring.datasource.username = dbUser
spring.datasource.password = password
My application with datasource default settings run well.
this is my code:
spring.datasource.url = ${db.url}
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
spring.datasource.username = dbUser
spring.datasource.password = dbPassword
Main class
@SpringBootConfiguration
public class IdsFeApplication implements ApplicationRunner{
private static final String FEC_CODEX = "A";
@Autowired
private static ConfigInfoDB infoDb;
@Autowired
private Login fec;
public static void main(String[] args) throws InterruptedException {
SpringApplication bootApp = new SpringApplication(IdsFeApplication.class);
bootApp.setBannerMode(Banner.Mode.OFF);
bootApp.setLogStartupInfo(false);
ConfigurableApplicationContext context = bootApp.run(args);
ConfigInfoDB db=context.getBean(ConfigInfoDB.class);
db.dbInfo();
}
@Override
public void run(ApplicationArguments args) throws Exception {
// TODO Auto-generated method stub
fec.token(FEC_CODEX);
}
}
Change your top annotation from @SpringBootConfiguration
to @SpringBootApplication
.
@SpringBootApplication
in reality is a shortcut for @configuration
, @EnableAutoConfiguration
and @ComponentScan
.
@EnableAutoConfiguration
does a lot of the magic behind the scenes of configuring your application based on what dependencies are included and what information it finds in the environment.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments