JAX-RS 和 Spring 中的自动装配注释

发布于 2024-12-11 14:03:43 字数 1276 浏览 0 评论 0原文

我正在尝试向我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永言不败 2024-12-18 14:03:43

您使用了错误的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 using com.sun.jersey.api.spring.Autowire (last image, very bottom of page), and from your message above, you are using org.springframework.beans.factory.annotation.Autowire which appears to be an Enum 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文