Failed to configure a DataSource from command line

Scripta14

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);


    }

}
jbx

Change your top annotation from @SpringBootConfiguration to @SpringBootApplication.

@SpringBootApplication in reality is a shortcut for @configuration, @EnableAutoConfiguration and @ComponentScan.

https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-using-springbootapplication-annotation.html

@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.

edited at
0

Comments

0 comments
Login to comment

Related

Failed to configure a DataSource: 'url'

Configure Client commands from command line

Configure wireless network from the command line

Springboot + JSP + Spring Security: Failed to configure a DataSource

Cannot resolve this error: Failed to configure a DataSource

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified

Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified

Failed to auto-configure a DataSource: 'spring.datasource.url'

How to configure a new NetworkManager connection from a shell script/command line?

Configure gnome-shell extensions from command line

Redis , configure redis.conf from command line

Get the number of passed and failed tests with their name from command line

Meteor Login Failed when used from command line

Failed to start an instrument test from Firebase gcloud command line

Configure DataSource from Java (without XML)

Failed to configure a DataSource: 'url' attribute is not specified using Spring Boot

Failed to configure a DataSource: Intellij Error when connecting Database to Spring Application

Configure a command line to execute on log in

Failed to obtain a cell from its DataSource

Spring Boot: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. SPRING

Config-Server Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

Gradle project --Failed to configure a DataSource'url' attribute is not specified and no embedded datasource could be configured

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Error In Gradle project

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Fa

Spring Boot jdbc issue. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

Spring Framework: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured for MongoDb