java – Spring @Resource Handling

I'm at @ L_ 502_ There was a problem with the field annotated @ resource in the 0 @ bean Yes) I have:

A field with setter method and annotated @ resource

< env entry > tags in my deployment descriptor (web. XML)

The application cannot start with beancreationexception. I don't want this because I don't necessarily want spring to inject spring managed beans I want spring to handle @ resource and retrieve JNDI resources

This is spring 2.5 6 sec03, the bean itself is an annotated @ service, which is used to automatically connect to other @ component instances In this case, the servlet container is Tomcat 7, but will eventually be deployed to Weblogic 10. Therefore, although I hope the ideal solution can be applied to both, Weblogic is necessary

Do I abuse this feature in spring 2.5? Generally speaking? Am I a little lost? I misunderstood something about JNDI? All the help was appreciated thank you.

Solution

If you are using spring stereotype annotations (@ service, @ component...), you may include < context: component scan / > elements to pick them in the spring configuration This is good, but it will automatically register commonannotationbeanpostprocessor in the application context as stated just above the second note in this link

The problem with the commonannotationbeanpostprocessor is that spring handles the @ resource annotation and will try to inject beans from its application context You can register your own commonannotationbeanpostprocessor bean and configure the bean by setting the alwaysusejndilookup property to true to tell spring to allow direct JNDI access to these @ resources

Note the notes in the linked document:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>