Simple repo to verify issue from stackoverflow.
What it verifies:
- We can set properties from starter.
- Then in Springboot project we use the starter, we can have the properties or override if we need.
Notice:
- We can't have two properties file with same name.
- Because of notice 1, we should name our properties something other than application.properties.
So the project that use our starter can have their properties name application.properties without mistakes.
How to use and verify:
-
Download this custom starter repo and run
mvn clean install
-
Inside another repo's pom.xml
<dependency> <groupId>gary.springframework</groupId> <artifactId>gary-custom-starter</artifactId> <version>0.0.1-SNAPSHOT</version> <dependency>
-
Include below code inside your repo , and let your application at least execute function tryGreet() it once. Watch logs from console, and see what you get.
@Autowired private Environment environment; @Value("${gary.name}") private String myName; @Autowired private Greeter greeter; public void tryGreet() { System.out.println("Your name is : " + myName); System.out.println(greeter.greet()); System.out.println("resolveException : " + environment.getProperty("spring.mvc.log-resolved-exception")); }
-
If you want override the value we set in starter, in your application.properties file.
gary.name=NAME-YOU-WANT
Restart your application again and see what you get from console.