NutzCN Logo
问答 ioc注入HttpClient的RequestConfig.Builder时提示类找不到
发布于 2529天前 作者 qq_b34a3274 2946 次浏览 复制 上一个帖子 下一个帖子
标签:

ioc.js配置如下部分内容:
requestConfigBuilder: {
type: "org.apache.http.client.config.RequestConfig.Builder",
fields: {
connectTimeout: { java: "$conf.get('http.connectTimeout')" },
connectRequestTimeout: { java: "$conf.get('http.connectRequestTimeout')" },
socketTimeout: { java: "$conf.get('http.socketTimeout')" }
}
},
requestConfig: {
type: "org.apache.http.client.config.RequestConfig",
factory: "$requestConfigBuilder#build"
},
报错内容:
org.nutz.ioc.IocException: IocBean[requestConfig -> requestConfigBuilder] For object [requestConfigBuilder] - type:[]
Caused by: org.nutz.ioc.ObjectLoadException: Wrong type name: 'org.apache.http.client.config.RequestConfig.Builder'
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.config.RequestConfig.Builder

该Builder是一个静态类,请问注入要怎样写呢?

5 回复

用 "插入代码" 按钮重新贴一次

ioc.js配置如下部分内容:

 requestConfigBuilder: {
 type: "org.apache.http.client.config.RequestConfig.Builder",
 fields: {
 connectTimeout: { java: "$conf.get('http.connectTimeout')" },
 connectRequestTimeout: { java: "$conf.get('http.connectRequestTimeout')" },
 socketTimeout: { java: "$conf.get('http.socketTimeout')" }
 }
 },
 requestConfig: {
 type: "org.apache.http.client.config.RequestConfig",
 factory: "$requestConfigBuilder#build"
 },

报错内容:
org.nutz.ioc.IocException: IocBean[requestConfig -> requestConfigBuilder] For object [requestConfigBuilder] - type:[]
Caused by: org.nutz.ioc.ObjectLoadException: Wrong type name: 'org.apache.http.client.config.RequestConfig.Builder'
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.config.RequestConfig.Builder

该Builder是一个静态类,请问注入要怎样写呢?

 requestConfigBuilder: {
     factory: "org.apache.http.client.config.RequestConfig#custom",
     fields: {
         connectTimeout: { java: "$conf.get('http.connectTimeout')" },
         connectRequestTimeout: { java: "$conf.get('http.connectRequestTimeout')" },
         socketTimeout: { java: "$conf.get('http.socketTimeout')" }
      }
 },

org.apache.http.client.config.RequestConfig.Builder 并非一个public类,没法直接new, 然后通过java代码的时候也是通过org.apache.http.client.config.RequestConfig.custom() 得到, 所以用factory解决

可以了,谢谢wendal

添加回复
请先登陆
回到顶部