I've been searching around and scratching my head for a few hours now, and I can't get it working.
I have a multi-module project with Gradle, currently with two modules: the BFF (using Spring Boot), and a module fetching some data from a database (inspired by this post). The structure looks something like this:
├── bff
| ├── build.gradle.kts
| ├── src
| └── main
| ├── java
| | └── some.package.bff.controller
| | └── CustomerController
| └── resources
| └── application.yaml
├── customer-service
| ├── build.gradle.kts
| ├── src
| └── main
| ├── java
| | ├── some.package.customer.config
| | | ├── CustomerServiceConfiguration
| | | └── CustomerServiceConfigurationProperties
| | └── ...
| └── resources
| └── customer-service-properties.yaml
├── build.gradle.kts
└── settings.gradle.kts
The CustomerServiceConfigurationProperties
is a simple ConfigurationProperties
class. The CustomerServiceConfiguration
class serves as a way to "import" the module into the BFF's Spring context, inspired by this post:
@Configuration
@EnableConfigurationProperties(CustomerServiceConfigurationProperties.class)
@PropertySource("classpath:customer-service-properties.yaml") //This fails
@ComponentScan(basePackages = {
"some.package.customer"
})
public class CustomerServiceConfiguration {
private static final Logger log = LoggerFactory.getLogger(CustomerServiceConfiguration.class);
private final CustomerServiceConfigurationProperties configurationProperties;
public CustomerServiceConfiguration(final CustomerServiceConfigurationProperties configurationProperties) {
this.configurationProperties = configurationProperties;
}
@Bean
SomeBean someBean() {
...
}
}
Adding properties mapped by CustomerServiceConfigurationProperties
to BFF's application.yaml
works as intended and are picked up to configure the Customer Service module. What doesn't work is adding configuration properties for the customer-service
module that shouldn't be modified by the bff
, e.g. Hibernate settings. I intend to do this using customer-service-properties.yaml
. When I try to run the application with the line in question, Spring complains that that file is not found on the classpath. Sure enough, when looking at the generated jar, it isn't there. Adding it to the bff
's resources works, but that's obviously not what I want.
Do I need to find a way to add the customer-service-properties.yaml
file to the classpath? Should I not use the classpath but rather something else for this? Am I simply trying to do something I shouldn't? Is there a different way to go about this?
Note: I'm still quite new to Gradle, if that's at all relevant.
Let me know if I need to add or specify something else. Any help or pointers will be appreciated. Thanks!