A
A
Araya2021-08-12 16:54:03
Spring
Araya, 2021-08-12 16:54:03

How to set up beans in subprojects without application.properties?

There is a certain library as a dependency of projects, it creates beans for working with databases (and not only). They require settings that are set in application.properties. In this project, of course, it's all there.

When connecting this lib to other projects, these beans do not take settings from their application.properties file, but wait for a footcloth in the current project. Shooting errors:

Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0;

Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'db.datasource.url' in value "${db.datasource.url}"


We have to copy-paste footcloths in all projects, which, naturally, is generally inconvenient. How to force beans to look into "their" application.properties file and get rid of copy-paste?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2021-08-13
@Araya

Araya , as colleague Yerlan Ibraev and I noted, it is worth raising a separate config server (Spring Cloud Config).
In this case, at the first start of the application, config server will start first. Then all other services (eureka server, gateway, etc.). All services will receive configs from config server. Moreover, you can directly get all the configs from the github repository. For each of the microservices, you can create your own properties || yml. Or you can set the general for all. You can also set individual configs according to the active profile. Also, if necessary, you can dynamically change the configs (for example, using the Spring Cloud Bus).
Here's a screenshot to help clarify the issue:
6116aa4e864f8269423104.png
You can move all configs from all microservices to a separate git repository (or you can store them locally. (profile - native)). Inside microservices, the bootstrap.yml or bootstrap.properties file is sufficient. Accordingly, you name all config files with the name of your microservice (pay attention to the screenshot above).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question