user770119
user770119

Reputation: 442

How to change expected datasource property name in Spring

I would like to change the expected property name in Spring for data source from:

spring.datasource.url: jdbc:oracle:thin:@127.0.0.1:151:xe

to:

com.foo.bar.spring.datasource.url: jdbc:oracle:thin:@127.0.0.1:151:xe

i.e. have a certain prefix for all spring properties in my application.

Is that possible? If so, how.

Thanks in advance!

Upvotes: 1

Views: 1303

Answers (1)

kaliyuga
kaliyuga

Reputation: 53

Write a configuration class where you instantate your DataSource per @Bean annotation like this:

@Configuration
public MyConfig {

    @Bean(name = "dataSource")
    @ConfigurationProperties(prefix = "com.foo.bar.spring.datasource")
    public DataSource dataSource() {
       DataSource dataSource = DataSourceBuilder.create().build();
       return dataSource;
    }
 }

this should do the trick..

see spring doc here:

Upvotes: 1

Related Questions