我们找到了非常好的简单解决方案。放入spring配置文件中必须放入:
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
<property name="alwaysUseJndiLookup" value="true" />
</bean>
这样一来,spring就能在JNDI中搜索以@Resource注释的bean。因此,现在可以做到:
@Resource(mappedName = MyBean.JNDI_NAME)
private MyBean myBean;