I have a class in which i want only one property to be injected from the properties file. The class is like this:
@Getter
public class BatchContext {
private final String city;
private final String channel;
@Value("${table.url: https://www.someurl.com}")
private final String url;
@Builder
public BatchContext(String city, String channel, @Value("${table.url:https://www.someurl.com}") String url) {
this.city = city;
this.channel = channel;
this.url = url;
}
}
I wanted to just pass country and segment to the BatchContext and wanted to load url from the properties file but the url turns out to be null, whats the best way to achieve this.
Madu, it seems your problem is related just to your class. It is not a Bean for Spring context, then your @Value cannot be injected by Spring.
Try setting your class as an object managed by Spring, e.g. @Component:
@Component
public class BatchContext {...
}