Jersey @InjectParam创建一个新对象,而不是从Spring获取 [英] Jersey @InjectParam creating a new Object instead of taking from Spring

查看:130
本文介绍了Jersey @InjectParam创建一个新对象,而不是从Spring获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Spring的Jersey应用程序 我正在使用 @InjectParam 希望(以及文档中写的是)Jersey从Spring容器中获取对象,但似乎Jersey正在创建对象而不是向Spring询问. .

I have a Jersey Application using Spring I am using the @InjectParam in the hope (and what is written in the documentation) that Jersey would obtain the object from the Spring Container, but it seems Jersey is creating the object instead of asking Spring for it.

有没有一种方法可以检查Spring IOC是否已在Jersey上注册?

Is there a way of checking if the Spring IOC is registered with Jersey ?

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:appContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>SpringDispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app> 

我的班级提供了对工厂的基本访问权限,但是工厂是新的

My class provide basic access to the factory but the factory is new

public FileStoreService(@InjectParam("dataAccessFactory") factory ) {  
   this.factory = factory;    
} 

并且我已经添加了 @Component ,仍然一无所获.

and i have added the @Component and still nothing.

推荐答案

使用了错误的servlet.应该是

The wrong servlet was being used. It should be

<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>

当前使用的是Jersey自己的容器,该容器仅使用默认构造函数创建对象. Spring Servlet允许Jersey附加到Spring容器.

The current one uses Jersey own container, which will only create objects using the default constructer. The Spring Servlet allows Jersey to attached to the Spring Container.

这篇关于Jersey @InjectParam创建一个新对象,而不是从Spring获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆