---
title: "太好了，jersey升级为1.0.1"
author: "wolf_19"
date: "2008-12-03T16:42:41Z"
tags: []
slug: "jersey-1-0-1"
draft: false
lastmod: "2008-12-03T16:42:41Z"
id: 285884
url: "https://wolfchina.iteye.com/blog/285884"
---

Jersey，一个REST风格服务的开发框架。

现在jersey从1.0升级了到了1.0.1,解决了广大的jerseyer抱怨的初始化Client时的耗时太长的问题。

以前使用jersey Client的时候，必须要先通过Client.create()来创建一下Client，我测试了一下，当我循环创建1000个Client时，耗时基本上达到了1分钟左右。

现在我们完全可以通过spring来注入一个Client，这样我们完全省略了Client.create()一步了。

这个是以前的代码

```
public Class ClientTestOld(){
    public String getHelloWorld(){
        String url = "http://localhost/helloworld";
        Client c = Client.create();
        WebResource r = c.resource(url);
        return r.get(String.class);
    }
}
```

 

现在的代码

```
public Class ClientTestNew(){
    @Resource
    private Client client;
    public String getHelloWorld(){
        String url = "http://localhost/helloworld";
        WebResource r = client.resource(url);
        return r.get(String.class);
    }
}
```

 

当然还需要在applicationContext.xml中加入如下配置：

```
<bean id="jerseyClient" class="com.sun.jersey.api.client.Client" />

<bean id="clientTest" class="com.tianji.www.jersey.client.ClientTestNew"
    p:client-ref="jerseyClient"
/>
```

 

pom.xml中jersey依赖也要改成1.0.1，不过jersey-spring现在还只是1.0.1-SNAPSHOT，要注意哦！