[Spring Env当类正在实现Callable接口[duplicate]

问题描述 投票:0回答:1
例如,我试图将环境类自动装配到客户类中。

public class Customer implements Callable<Person> { @Autowired private Environment env; //dao logic }

还有我的主要方法,例如:

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

但是当我尝试自动装配Customer类中的Environment时,该实例返回null。我认为这是因为我的Customer类正在实现Callable iterface,但不确定为什么env为null。 

任何想法都值得赞赏。

java spring callable
1个回答
0
投票
使Customer类为bean,并在需要时通过自动装配来使用它。

@Component public class Customer implements Callable<List<Person>> { @Autowired private Environment env; //dao logic }

© www.soinside.com 2019 - 2024. All rights reserved.