1
我已经定义HashMap
HashMap的
<bean id="userMap" class="pl.test.pojo.UserMap">
<property name="userMap">
<map>
</map>
</property>
</bean>
我希望能够访问我的项目从任何类此内容 我写它喜欢:
@Autowired
UserMap userMap;
Status s = new Status();
User req = new User();
s.setStatus(3);
s.setErrorCode("0");
s.setErrorDescription("OK");
s.setCorrelationId(addToQuarantineRequest.getCorrelationId());
userMap.getUserMap().put(req, s);
,它是可以的,但是从另外一个班级我想要读取userMap
的内容首先用@autowired
注释说明我有NullPointerException
我怎样才能让Map
从整个项目中获得?
getter和setter方法? –
@JordiCastilla我不太了解。类'UserMap'确实有getter和setter。我不知道这与可访问性有什么共同点 – Mithrand1r
如果您没有正确设置Spring配置以使用'Autowired',NPE就会发生。你有没有在你的Spring xml配置中指定' '位? –