1
@Configuration
@ComponentScan
@PropertySource("classpath:tests.properties")
public class SomeConfig {

    @Value("${platformVersion}")
    private String platformVersion;

    @Resource
    private Environment environment;

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfig() {
       return new PropertySourcesPlaceholderConfigurer();
    }
}

The platformVersion and environment are always null. In the logs: Adding [class path resource [tests.properties]] PropertySource with lowest search precedence. I saw other posts on stackoverflow (Autowired Environment is null), I do not want to go with implementing EnvironmentAware. Changing private to public for Environment does not solve the problem. Any other ideas are welcome!

Maksim
  • 1,231
  • 1
  • 15
  • 25

1 Answers1

0

The environment is null because I use a custom test scope (see this post for details https://peterkedemo.wordpress.com/2013/03/30/writing-good-selenium-tests-with-page-objects-and-spring/). After I remove the scope, environment is injected well. Do you have some ideas why?

Maksim
  • 1,231
  • 1
  • 15
  • 25