I created a multi module maven project that contains the library
module (spring boot starter application) and application
module (spring boot application that have included library
as a dependency).
This is the structure of my project:
.
├── application
│ ├── pom.xml
│ └── src
│ ├── main
│ │ ├── kotlin
│ │ │ └── com
│ │ │ └── application
│ │ │ ├── ApplicationService.kt
│ │ │ └── Application.kt
│ │ └── resources
│ │ └── application.properties
│ └── test
│ └── kotlin
│ └── com
│ └── application
│ └── ApplicationServiceTest.kt
├── library
│ ├── pom.xml
│ └── src
│ └── main
│ ├── kotlin
│ │ └── com
│ │ └── application
│ │ ├── LibraryService.kt
│ │ └── Properties.kt
│ └── resources
│ ├── META-INF
│ │ └── spring.factories
│ └── config
│ └── application.properties
└── pom.xml
library/.../Properties.kt:
@ConfigurationProperties("properties")
class Properties {
lateinit var name: String
}
library/.../LibraryService.kt:
@Service
@EnableConfigurationProperties(Properties::class)
class LibraryService(private val properties: Properties) {
fun name() = properties.name
}
library/.../spring.factories:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.application.LibraryService
library/.../config/application.properties:
properties.name=library
application/.../Application.kt
@SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
application/.../ApplicationService.kt
@Service
class ApplicationService(private val libraryService: LibraryService) {
fun call() = libraryService.name()
}
application/.../application.properties
properties.name=application
So, I have the library
module where I put application.properties
file with default parameter properties.name=library
. The library
module has Property
class injected in LibraryService
. LibraryService
has the simple method name()
that just returns value from property. I also have application
module where I use LibraryService
in ApplicationService
and invoke name()
function, but I have application.properties
in application
module where properties.name=application
.
I expect that application's
properties.name=application
overrides library's
properties.name=library
and ApplicationService::call
must return value application
instead of default value library
in properties.name
in library module
. But this does not happen. ApplicationService::call
returns value library
.
I created simple junit test to reproduce this behaviour (ApplicationServiceTest.kt):
@SpringBootTest
class ApplicationServiceTest {
@Autowired
lateinit var applicationService: ApplicationService
@Test
fun test() {
println(applicationService.call())
}
}
It prints library
. I would like to have the following behaviour: library
has some several defined default properties, but I want to be able to override some of these properties in application
. How to achieve that?
source code: https://github.com/grolegor/maven-multi-module-spring-starter