Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Spring datasource url parameter is not written in System properties (works only locally) #1277

Open
regrog opened this issue Nov 15, 2024 · 1 comment

Comments

@regrog
Copy link

regrog commented Nov 15, 2024

Type: Bug

Component: Parameter Store
io.awspring.cloud:spring-cloud-aws-starter-parameter-store version 3.2.1

Describe the bug
I'm importing my params from the store:

(DeferredLog.java:251) - Bean of type AwsClientConfigurerParameterStore is not registered: io.awspring.cloud.autoconfigure.config.parameterstore.AwsParameterStoreClientCustomizer has not been registered
(DeferredLog.java:252) - Loading property from AWS Parameter Store with name: /config/my-app_stag/, optional: false
(DeferredLog.java:251) - Populating property retrieved from AWS Parameter Store: spring.datasource.password
(DeferredLog.java:251) - Populating property retrieved from AWS Parameter Store: spring.datasource.url
(DeferredLog.java:251) - Populating property retrieved from AWS Parameter Store: spring.datasource.username

Params:

/config/my-app_stag/spring/datasource/url
/config/my-app_stag/spring/datasource/password
/config/my-app_stag/spring/datasource/username

My problem is that testing locally the System property values are correctly evaluated from the parameter store. example:

spring.datasource.url=jdbc:mysql://my_db

But when I deploy my app to ECS, reading url (and others) value from System.property result in empty string:

spring.datasource.url=

The result is that the hikari DataSource class initialization fails because there is no DB url.
This is the way I create the datasource:

	@Primary
	@ConfigurationProperties("spring.datasource")
	public DataSourceProperties dataSourceProperties() {
		return new DataSourceProperties();
	}

	@Bean(name = "hikariDataSource")
	@ConfigurationProperties(prefix = "spring.datasource.hikari") // set hikari specific properties
	public HikariDataSource hikariDataSource(final DataSourceProperties properties) {
		return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
	}

	@Bean(name = "dataSource")
	@Primary
	public DataSource dataSource(final HikariDataSource hikariDataSource) {
		return hikariDataSource;
	}
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine suitable jdbc url

Is it something related to order initialization?
Or something related?
I can't figure out what to do with this problem.

Thanks

@regrog
Copy link
Author

regrog commented Nov 15, 2024

After days of debug I found the problem.
It's related to spring profile and the various application.yaml.

I'm working with 2 profiles:

  • local for local execution
  • stag for test and deploy in AWS

mail application.yml:

spring:
  datasource:
    url: url_to_db
    username: foo
    password: bar

application-local.yml:
does not contains any spring parameters, it's everything in the main file

application-stag.yml:

spring:
  datasource:
    url:
    username:
    password:

As you can see in application-stag.yml I have empty properties, they are just a placeholder.

So when I run the app locally, the datasource url is retrieved and replaced from the param store.
BUT when I run the app in AWS the application file for the stag profile overrides the freshly read parameter from the store.
Deleting the placeholders in application-stag.yml did the trick, but I think this isn't good.

Could be related to this issue: #1110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant