`
wolf_19
  • 浏览: 164304 次
社区版块
存档分类
最新评论

太好了,jersey升级为1.0.1

阅读更多

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,要注意哦!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics