【发布时间】:2017-09-21 13:43:17
【问题描述】:
我需要将地图设置为 spring bean。我有一个使用 @PostConstruct 关键字在 init() 方法中初始化的地图。
public class CustomerService
{
@Autowired
TestService testService;
static Map<String, String> someMap;
@PostConstruct
public void initIt() throws Exception {
someMap = new HashMap<String, String>();
someMap = // some code by calling testService
}
@PreDestroy
public void cleanUp() throws Exception {}
}
我从 applicationContext.xml 将其称为 bean。
<bean id="customerService" class="test.com.customer.CustomerService"/>
初始化映射工作正常,我需要将此映射的值分配给 bean,以便在应用程序的其他位置访问 bean 的值。
我找到了将地图设置为 bean 的示例,但所有这些都是在 XML 配置中完成的。 How to inject a Map in java springs
我怎样才能完成这项任务。任何知识都受到高度赞赏。
【问题讨论】:
标签: java spring spring-mvc dictionary