@Resource private URL someUrl; public void setSomeUrl(URL someUrl) { this.someUrl = someUrl; }
< env-entry>我的部署描述符中的标记(web.xml)
<env-entry> <env-entry-name>someUrl</env-entry-name> <env-entry-type>java.net.URL</env-entry-type> <env-entry-value>http://somedomain.net/some/path</env-entry-value> </env-entry>
应用程序无法以BeanCreationException开始,我不希望这是因为我不一定希望spring注入Spring管理的bean.我希望Spring处理@Resource并检索JNDI资源.
这是Spring 2.5.6SEC03,bean本身是带注释的@Service,用于自动连接到其他@Component实例.在这种情况下,Servlet容器是Tomcat 7,但最终将部署到Weblogic 10上,所以虽然我希望理想的解决方案同时适用于两者,但Weblogic是必备的.
解决方法
CommonAnnotationBeanPostProcessor
.
包含CommonAnnotationBeanPostProcessor的问题是Spring处理@Resource注释并将尝试从其应用程序上下文中注入bean.您可以注册自己的CommonAnnotationBeanPostProcessor bean,并通过将alwaysUseJndiLookup属性设置为true来配置bean,从而告诉Spring允许直接JNDI访问这些@ Resource.
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"> <property name="alwaysUseJndiLookup" value="true"/> </bean>
请注意链接文档中的注释:
NOTE: A default CommonAnnotationBeanPostProcessor will be registered by the “context:annotation-config” and “context:component-scan” XML tags. Remove or turn off the default annotation configuration there if you intend to specify a custom CommonAnnotationBeanPostProcessor bean deFinition!
原文地址:https://www.jb51.cc/java/129913.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。