I have used spring.config.import feature to import values from AWS parameter store in my springboot application. But not able to access the imported values in my service class. Please help.
In aws param store, I have below values:
/config/my-project/preset/onboarding = app,scan,shop
/config/my-project/preset/onload = redeem,notification
application.yml
spring:
config:
import:
- "optional:aws-parameterstore:/config/my-project/preset"
In my Java class, trying to access env variables:
import org.springframework.core.env.Environment;
@Component
public class DataService {
@Autowired
private Environment env;
public MemberData getPresetData(final String preset) {
log.info("preset => " + preset); /* preset = onboarding */
String fields = env.getProperty(preset);
log.info("fields => " + fields); /* fields prints as null */
String fields = env.getProperty("/config/my-project/preset/onboarding");
log.info("fields => " + fields); /* fields prints as null */
}
}
build.gradle =>
springboot version 3.1.1
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:4.0.3'
implementation 'io.awspring.cloud:spring-cloud-aws-starter-parameter-store:3.0.1'
implementation 'io.awspring.cloud:spring-cloud-aws-starter-secrets-manager:3.0.1'