NutzCN Logo
问答 Nutz集成ehcache问题。
发布于 2865天前 作者 fangjingping 2043 次浏览 复制 上一个帖子 下一个帖子
标签:
[DEBUG] 16:54:55.186 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [GET] path=/faction/test2 : FactionService.testToken(FactionService.java:38)
[DEBUG] 16:54:55.187 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'factionService'<class com.xueersi.apc.service.FactionService>
[DEBUG] 16:54:55.187 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) - 	 >> Load definition name=factionService
[DEBUG] 16:54:55.187 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) - Found IocObject(factionService) in AnnotationIocLoader(packages=[com.xueersi.apc])
[DEBUG] 16:54:55.188 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) - 	 >> Make...'factionService'<class com.xueersi.apc.service.FactionService>
[DEBUG] 16:54:55.188 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) - Load class com.xueersi.apc.service.FactionService without AOP
[DEBUG] 16:54:55.188 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) - Save object 'factionService' to [app] 
[DEBUG] 16:54:55.189 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'dao'<interface org.nutz.dao.Dao>
[DEBUG] 16:54:55.189 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'cacheManager'<class net.sf.ehcache.CacheManager>
[DEBUG] 16:54:55.189 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) - 	 >> Load definition name=cacheManager
[DEBUG] 16:54:55.189 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) - Loading define for name=cacheManager
[DEBUG] 16:54:55.190 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) - Found IocObject(cacheManager) in JsonLoader(paths=[ioc/])
[DEBUG] 16:54:55.190 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) - 	 >> Make...'cacheManager'<class net.sf.ehcache.CacheManager>
[DEBUG] 16:54:55.206 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) - Load class net.sf.ehcache.CacheManager without AOP
[DEBUG] 16:54:55.206 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) - Save object 'cacheManager' to [app] 
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[DEBUG] 16:54:55.229 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:84) - Remove object 'cacheManager' from [app] 
[DEBUG] 16:54:55.229 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:84) - Remove object 'factionService' from [app] 
[WARN ] 16:54:55.230 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/faction/test2 :
org.nutz.ioc.IocException: [factionService, cacheManager] # FAIL to create Ioc Bean name=[cacheManager]
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.lang.born.BorningException: Fail to born 'net.sf.ehcache.CacheManager'
 by args: [] because:
org.xml.sax.SAXException: null:21: Could not finish element <cache>. Message was: java.lang.NullPointerException
	at org.nutz.lang.born.MethodBorning.born(MethodBorning.java:20)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
	... 28 more
Caused by: org.xml.sax.SAXException: null:21: Could not finish element <cache>. Message was: java.lang.NullPointerException
	at net.sf.ehcache.config.BeanHandler.addChild(BeanHandler.java:400)
	at net.sf.ehcache.config.BeanHandler.endElement(BeanHandler.java:135)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1783)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2970)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
	at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
	at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:157)
	at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:103)
	at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:140)
	at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:892)
	at net.sf.ehcache.CacheManager.create(CacheManager.java:873)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.nutz.lang.born.MethodBorning.born(MethodBorning.java:17)
	... 30 more

以上是log
下面是调用报错的代码:

package com.apc.service;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Ok;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

@IocBean
@At("/faction")
@Fail("http:500")
public class FactionService {

//	@Inject
//    protected Dao dao;
//	
//	
//	@At("/test")
//	@Ok("json")
//	public int testTableCount(){
//		int count = 0;
//		count = dao.count(Faction.class);
//		return count;
//	}
	@Inject
	private CacheManager cacheManager;
	
	@At("/test2")
	@Ok("raw:json")
	public String testToken(){
		Cache cache = cacheManager.getCache("configCache");
		Element value = cache.get("fangjingping");
		if(null == value){
			cache.put(new Element("fangjingping", "haha,this is value"));
			return "this is no value";
		}else{
			return value.toString();
		}
	}
}

下面是js文件以及ehcache.xml

var ioc = {
    // 直接初始化Ehcache,默认找ehcache.xml文件哦
    cacheManager : {
        type : "net.sf.ehcache.CacheManager",
        factory : "net.sf.ehcache.CacheManager#create"
    }
    /* // 与shiro共享一个ehcache示例的方式
    cacheManager : {
        type : "net.sf.ehcache.CacheManager",
        factory : "net.sf.ehcache.CacheManager#getCacheManager",
        args : ["nutzbook"] // 对应shiro.ini中指定的ehcache.xml中定义的name
    }
     */
};


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
<!-- <diskStore path="c:\\mdcp_temp" />-->
 <cacheManagerEventListenerFactory class="" properties="" />
 
 <defaultCache>
        maxElementsInMemory="20"
        eternal="false"
        overflowToDisk="false"
        timeToIdleSeconds="7190" 
        timeToLiveSeconds="7190"
 </defaultCache>  
 
<cache>
        name="configCache"
        maxElementsInMemory="100"
        maxElementsOnDisk="1000" 
        eternal="true"
        overflowToDisk="false"
        timeToIdleSeconds="5" 
        timeToLiveSeconds="6"
</cache>

</ehcache>
4 回复

用的是ehcache 2.10.2

xml写错了个, 右括折号的位置不对

<cache
        name="configCache"
        maxElementsInMemory="100"
        maxElementsOnDisk="1000" 
        eternal="true"
        overflowToDisk="false"
        timeToIdleSeconds="5" 
        timeToLiveSeconds="6">
</cache>

defaultCache也是这个问题

建议拷贝默认ehcache.xml来改,得符合xml的格式要求

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