Reputation: 722
I have written a spring boot app to monitor jobs and have wired the configuration properties for the clients to call services in the job services. I am using a yml file called application-test.yml in src/test/resources. I have also set the active profiles when running the test to -Dspring.profiles.active='test' and spring says the active profile is test. However when I run the tests, the configuration properties host and path are always null. Here is my configuration file:
spring:
profiles: test
myservices: clients:
printservice:
host: app/sms/appdev.com
path: jobs/{jobId}
monitorNgService:
host: app/monitor/appdev.com
path: iqueue/jobs/{jobKey}/servers
Here are my classes for the configurations:
@Configuration
@ConfigurationProperties(prefix="myservices.clients")
class PrintServiceProperties{
String host;
String path;
}
The other configuration class loads the second configuration in the yml file. It also has null for host and path. Here is that file;
@Configuration
@ConfigurationProperties(prefix="myservices.clients")
class MonitorNgServiceProperties{
String host;
String path;
}
I am injecting this class in a class that uses these properties but they are null
Here is the class
@Service
@Import(MonitorNgServiceProperties)
@Slf4j
class MonitorService implements InitializingBean{
@Autowired
MonitorNgServiceProperties monitorNgService
I have spent hours on this but can't figure out why the properties won't load. I'd be really grateful for help in resolving this issue
Upvotes: 1
Views: 157
Reputation: 722
The problem was that I was missing the last prefix:
@ConfigurationProperties(prefix="myservices.clients.printservice")
Upvotes: 1