Have couple of fields annotated with @Value within the @Service Class. These fields are not getting populated properly and are null. Perhaps I overlooked something, I have pasted the relevant blocks of code below. Tried the alternative option env.getProperty() with same result.
The value of following properties in output are null.
package com.project.service.impl; import org.springframework.beans.factory.annotation.Value @Service("aService") @PropertySource(value="classpath:app.properties") public class ServiceImpl implements Service{ private Environment environment; @Value("${list.size}") private Integer list1; @Value("${list2.size}") private Integer list2Size; @Autowired public ServiceImpl(StringRedisTemplate stringTemplate){ this.stringTemplate = stringTemplate; logger.info("TESTING 123: "+list1); } // ... } @EnableWebMvc @ComponentScan(basePackages = {"com.project.service","..."}) @Configuration public class ServletConfig extends WebMvcConfigurerAdapter { // ... @Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer(); Resource[] resources = new ClassPathResource[] { new ClassPathResource("app.properties") }; propertyPlaceholderConfigurer.setLocations(resources); propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true); return propertyPlaceholderConfigurer; } }
ignoreUnresolvablePlaceholderstofalseso you can see if other properties are not found. where in your projectstucture isapp.properties. Have you triednew ClassPathResource("/app.properties")