JAX-RS 和 Spring 中的自动装配注释
我正在尝试向我的 Spring 3 + Hibernate 应用程序添加 REST 支持。
我已经使用 Netbeans 的向导创建了 REST 支持,它在我的 Resource 类上方放置了 @Autowire 注释(不是 @autowired)。从 Spring 获取 @Autowire 注释会导致错误
incompatible types
found : org.springframework.beans.factory.annotation.Autowire
required: java.lang.annotation.Annotation
Getting @Autowire from JAX-RS should be only for Spring 2.5 据我了解 这里。如果包含它,我会收到以下错误,我认为这与加载 Spring 2.5 有关:
SEVERE: Exception while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception
parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml];
nested exception is java.lang.NoSuchMethodError:
org.springframework.beans.MutablePropertyValues.add(Ljava/lang/String;Ljava/lang/
Object;)Lorg/springframework/beans/MutablePropertyValues;
有人能指出我如何添加此注释,并使 JAX-RS 与 Spring 配合使用吗?另外,我使用了 SessionFactory,自动生成的代码引用了应用程序上下文中的entityManagerFactory。这些可以互换使用吗?
PS:请允许我说,在我三周的平台之旅中,到目前为止,我非常讨厌 Java EE,在各个层面上都是主要的绊脚石,对于咆哮感到抱歉。
I am trying to add REST support to my Spring 3 + Hibernate application.
I have created the REST support using the wizard from Netbeans, at it has put a @Autowire annotation (not @autowired) above my Resource class. Getting the @Autowire annotation from Spring causes the error
incompatible types
found : org.springframework.beans.factory.annotation.Autowire
required: java.lang.annotation.Annotation
Getting @Autowire from JAX-RS should be only for Spring 2.5 as far as I understand from here. I get the following error if I include it, which I think is related to Spring 2.5 being loaded:
SEVERE: Exception while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception
parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml];
nested exception is java.lang.NoSuchMethodError:
org.springframework.beans.MutablePropertyValues.add(Ljava/lang/String;Ljava/lang/
Object;)Lorg/springframework/beans/MutablePropertyValues;
Could someone point me on how to add this annotation, and make JAX-RS work with Spring? Also, I was using a SessionFactory and the autogenerated code refers to a entityManagerFactory in the applicationcontext. Can those be used interchangingly?
PS: Allow me to say that I hate Java EE with a passion so far in my three week journey with the platform, major stumbling blocks at every level, sorry for the rant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用了错误的
Autowire
。 “Netbeans REST 向导”看起来会使用com.sun.jersey。 api.spring.Autowire
(最后一张图片,页面最底部),从上面的消息中,您正在使用org.springframework. beans.factory.annotation.Autowire
似乎是 Spring 2.0 中使用的Enum
。据我所知,这可能是 Spring 2.0 特有的事情。也许你应该看看自己做 REST JAX-RS 的东西 (使用泽西岛),因为这并不那么困难。
You are using the wrong
Autowire
. The 'Netbeans REST wizard' looks like it would be usingcom.sun.jersey.api.spring.Autowire
(last image, very bottom of page), and from your message above, you are usingorg.springframework.beans.factory.annotation.Autowire
which appears to be anEnum
used in Spring 2.0.From what I can tell, this may be a specific thing to Spring 2.0 anyways. Perhaps you should take a look at doing the REST JAX-RS stuff yourself (using Jersey), as it is not that difficult.