NutzCN Logo
问答 xml文件转js 配置ioc
发布于 2937天前 作者 Rekoe 1576 次浏览 复制 上一个帖子 下一个帖子
标签:

这个怎么用js配置

<!-- Jedis 连接池配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
  <property name="maxTotal" value="2000" />
  <property name="maxIdle" value="100" />
  <property name="minIdle" value="50" />
  <property name="maxWaitMillis" value="2000" />
  <property name="testOnBorrow" value="false" />
  <property name="testOnReturn" value="false" />
  <property name="testWhileIdle" value="false" />
</bean>
<bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool">
  <constructor-arg ref="jedisPoolConfig" />
  <constructor-arg>
    <list>
      <bean class="redis.clients.jedis.JedisShardInfo">
      <constructor-arg value="${redis1.host}" />
      <constructor-arg type="int" value="${redis1.port}" />
      <constructor-arg value="instance:01" />
    </bean>
    <bean class="redis.clients.jedis.JedisShardInfo">
      <constructor-arg value="${redis2.host}" />
      <constructor-arg type="int" value="${redis2.port}" />
      <constructor-arg value="instance:02" />
    </bean>
    <bean class="redis.clients.jedis.JedisShardInfo">
      <constructor-arg value="${redis3.host}" />
      <constructor-arg type="int" value="${redis3.port}" />
      <constructor-arg value="instance:03" />
    </bean>
    </list>
  </constructor-arg>
</bean>
16 回复

jedis? 本站源码就有啦

var ioc = {
// 参考 https://github.com/xetorthio/jedis/wiki/Getting-started
		jedisPoolConfig : {
			type : "redis.clients.jedis.JedisPoolConfig",
			fields : {
				testWhileIdle : true, // 空闲时测试,免得redis连接空闲时间长了断线
				maxTotal : 100 // 一般都够了吧
			}
		},
		jedisPool : {
			type : "redis.clients.jedis.JedisPool",
			args : [
			        {refer : "jedisPoolConfig"},
			        // 从配置文件中读取redis服务器信息
			        {java : "$conf.get('redis.host', 'localhost')"}, 
			        {java : "$conf.getInt('redis.port', 6379)"}, 
			        {java : "$conf.getInt('redis.timeout', 2000)"}, 
			        {java : "$conf.get('redis.password')"}, 
			        {java : "$conf.getInt('redis.database', 0)"}
			        ],
			fields : {},
			events : {
				depose : "destroy" // 关闭应用时必须关掉呢
			}
		}
};

他那个是配置了多个源
我暂时按照本站的一个源的试试
@wendal
还有个xml的配置关于aop 的 怎么翻译成nutz的格式

<aop:config proxy-target-class="true">
  <aop:aspect ref="cachePointCut">
    <aop:pointcut id="daoCachePointcut" expression="execution(public !void com.jarvis.cache_example.common.dao..*.*(..)) &amp;&amp; @annotation(cache)" />
    <aop:around pointcut-ref="daoCachePointcut" method="proceed" />
  </aop:aspect>
  <aop:aspect ref="cachePointCut" order="1000"><!-- order 参数控制 aop通知的优先级,值越小,优先级越高 ,在事务提交后删除缓存 -->
    <aop:pointcut id="deleteCachePointcut" expression="execution(* com.jarvis.cache_example.common.dao..*.*(..)) &amp;&amp; @annotation(cacheDelete)" />
    <aop:after-returning pointcut-ref="deleteCachePointcut" method="deleteCache" returning="retVal"/>
  </aop:aspect>
</aop:config>
shardedJedisPool : {
  type : "redis.clients.jedis.ShardedJedisPool",
  args : [{refer:"jedisPoolConfig"},
  		[
		  {
		    type : "redis.clients.jedis.JedisShardInfo",
			args : [java: "conf.get('redis1.host')", 6379, "instance:01"]
		  },
		  {
		    type : "redis.clients.jedis.JedisShardInfo",
			args : [java: "conf.get('redis2.host')", 6379, "instance:02"]
		  },
		  {
		    type : "redis.clients.jedis.JedisShardInfo",
			args : [java: "conf.get('redis3.host')", 6379, "instance:03"]
		  },
		]
  ],
}

xml中的aop翻译, 基本上JsonAopConfigration

$aop_mycache : {
    type : "org.nutz.ioc.aop.config.impl.JsonAopConfigration",
	fields : {
        itemList : [
		     "com.jarvis.cache_example.common.dao.+", ".+", "ioc:cachePointCut"
		]
	}
},
cachePointCut : {
    type : "xx.x.x.x.x.x.xxx" // 实现MethodInterceptor
}

@wendal(wendal)

<aop:after-returning pointcut-ref="deleteCachePointcut" method="deleteCache" returning="retVal"/>

这个是控制先后顺序的么

细分的切入点, 参考 AbstractMethodInterceptor

他这类如何翻译成nutz的 aop 实现

/**
 * 如果要在Mybatis 的mapper上使用@Cache 及@CacheDelete 注解时,需要使用些类获取注解实例 弊端:mapper中的所有方法都会进入此切面 &lt;aop:config proxy-target-class="false"&gt;
 * 配置中 proxy-target-class 必须设置为false
 * @author jiayu.qiu
 */
public class CachePointCutProxy {

    private AbstractCacheManager cacheManager;

    public AbstractCacheManager getCacheManager() {
        return cacheManager;
    }

    public void setCacheManager(AbstractCacheManager cacheManager) {
        this.cacheManager=cacheManager;
    }

    public Object proceed(ProceedingJoinPoint pjp) throws Throwable {
        Signature signature=pjp.getSignature();
        MethodSignature methodSignature=(MethodSignature)signature;
        Method method=methodSignature.getMethod();
        if(method.isAnnotationPresent(Cache.class)) {
            Cache cache=method.getAnnotation(Cache.class);// method.getAnnotationsByType(Cache.class)[0];
            return cacheManager.proceed(pjp, cache);
        }

        try {
            return pjp.proceed();
        } catch(Throwable e) {
            throw new Exception(e);
        }
    }

    public void deleteCache(JoinPoint jp, Object retVal) {
        Signature signature=jp.getSignature();
        MethodSignature methodSignature=(MethodSignature)signature;
        Method method=methodSignature.getMethod();
        if(method.isAnnotationPresent(CacheDelete.class)) {
            CacheDelete cacheDelete=method.getAnnotation(CacheDelete.class);
            cacheManager.deleteCache(jp, cacheDelete, retVal);
        }
    }
}

@wendal(wendal)

感觉 没办法搞了

@Rekoe 感觉没办法搞? 不会吧, 哪个方法翻译不了? 看上去就是一堆取注解,然后调用cacheManager的方法

@wendal(wendal)
这个类好像是 原始的aop中的类
如果改动的少的话 需要把这个类创建出来
ProceedingJoinPoint

InterceptorChain等同于ProceedingJoinPoint,方法运行需要的东西,都包含

@wendal(wendal)
我看了下 用到了
属性

Signature

这个该如何通过InterceptorChain获得

Signature 看不出有啥用, 我看到是它后面从method取注解, 能取注解不就好了, 管他Signature是啥东西

@wendal(wendal)
他好像是在找 某个 类某个方法 这两个属性
也就是它在定位执行的方法所在 的类 获得这两个值

遍历所有方法一样能找到吧?

@wendal(wendal) 找到他需要的值了

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