'Is it possible to access a property value from another maven project?
I have a SpringBoot service:
package test;
@Service
public class TestService {
@Value("${service.readTimeout}")
private Duration readTimeout;
}
service.readTimeout
is not declared in my current project's property files. It is linked in a separate project, which are all marked as Maven modules.
How is the value from the other property file being accessed by this project ?
The project is not listed as a dependency or mentioned in the pom.xml
for the project that is using the value.
Does Maven connect all declared modules ? Are all files accessible from all projects ?
What is going on here ?
Solution 1:[1]
To get an external ressource you can use FileSystemResource
, for example I have two projects demo
and demo2
:
So I want to have access to demo
application.properties from demo2
,so you can use this code :
Resource resource = new FileSystemResource("absolute path");
// for example : C:\\Users\\Developper\\eclipse workspace\\demo\\src\\main\\resources\\application.properties
Properties props = PropertiesLoaderUtils.loadProperties(resource);
System.out.println(props);
If you are forced to use annotations, you can try : @PropertySource("file:/path/to/propertiesfile")
: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |