@Inject
和
Mvcs.ctx().getDefaultIoc().get(CloudBindService.class);
有什么区别啊?
15 回复
我在初始化时
Ioc ioc = config.getIoc();
Dao dao = ioc.get(Dao.class);
// 初始化数据表
initSysData(config, dao);
// 初始化系统变量
initSysSetting(config, dao);
// 初始化定时任务
initSysTask(config, dao);
// 初始化自定义路由
initSysRoute(config, dao);
// 初始化热插拔插件
initSysPlugin(config, dao);
initInitMq(config, dao);
用到了redis
@IocBean(args = { "refer:dao" })
public class RabbitmqService extends Service {
private static final Log log = Logs.get();
@Inject
SysUnitService unitservice;
@Inject
SysUserService userservice;
@Inject
SysRoleService sysRoleService;
@Inject
RedisService redisService;
redis的连接数设置了100,怎么有时会获得不到连接
开发环境没这问题,只有测试时会出现。。。。
protected Ioc createIoc(NutConfig config, Class<?> mainModule) throws Exception {
IocBy ib = mainModule.getAnnotation(IocBy.class);
if (null != ib) {
if (log.isDebugEnabled())
log.debugf("@IocBy(type=%s, args=%s,init=%s)",
ib.type().getName(),
Json.toJson(ib.args()),
Json.toJson(ib.init()));
Ioc ioc = Mirror.me(ib.type()).born().create(config, ib.args());
// 如果是 Ioc2 的实现,增加新的 ValueMaker
if (ioc instanceof Ioc2) {
((Ioc2) ioc).addValueProxyMaker(new ServletValueProxyMaker(config.getServletContext()));
}
// 如果给定了 Ioc 的初始化,则依次调用
for (String objName : ib.init()) {
ioc.get(null, objName);
}
// 保存 Ioc 对象
Mvcs.setIoc(ioc);
return ioc;
} else if (log.isInfoEnabled())
log.info("!!!Your application without @IocBy supporting");
return null;
}
loader:/*ComboIocLoader*/
{
"paths": ["config/ioc/"],
"map": {
"imageUpload": {
"type": "org.nutz.mvc.upload.UploadAdaptor",
"singleton": false,
"args": [{
"refer": "uploadImageContext"
}]
},
"redis": {
"type": "org.nutz.integration.jedis.RedisInterceptor",
"fields": {
"jedisAgent": {
"refer": "jedisAgent"
}
}
},
"dataSource": {
"factory": "$conf#make",
"args": ["com.alibaba.druid.pool.DruidDataSource", "db."],
"type": "com.alibaba.druid.pool.DruidDataSource",
"events": {
"create": "init",
"depose": "close"
}
},
这个,假设我的imageUpload方法里面调用了redis,他会在redis没初始化就调用吗?
跟这个问题一样: https://nutz.cn/yvr/t/0gcpbqttqij5hpcik961uqsc12
你可以换成最新的redis插件快照版
添加回复
请先登陆