2

I am trying to Autowire Environment class into my class Customer for example.

public class Customer implements Callable<Person> {

@Autowired
private Environment env;

//dao logic

}

Also I have my main method like:

@Configuration
@ComponentScan({"org.test"})
@PropertySource("classpath:app.properties")
public class Application {
}

But when I try to autowire Environment in Customer class , the instance returns null. I assume it is because my Customer class is implementing Callable iterface but not sure why the env is null.

Any thoughts are appreciated.

Brooklyn99
  • 987
  • 13
  • 24
  • @M.Denium, I think mine is a more specific case.Because if i remove the implements Callable it works fine. I can load the env but when I implement it does not work. – Brooklyn99 Mar 05 '20 at 15:21

1 Answers1

0

Make the Customer class a bean and use it by autowiring it where-ever required.

@Component
public class Customer implements Callable<List<Person>> {

    @Autowired
    private Environment env;

    //dao logic

}