如何解决警告信息:"没有找到配置。"

时间:2015-02-02 05:06:20

标签: java spring tomcat lucene

我想进行测试以获取Analyzer和Directory的值,但控制台显示以下警告消息:

WARN - No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/shop1/WebRoot/WEB-INF/lib/ehcache-1.2.3.jar!/ehcache-failsafe.xml
Analyzer:null
configurationnull

My Spring配置:

<bean id="configuration" class="cn.cultivator.shop1.lucene.Configuration" init-method="init">
        <property name="dirPath" value="C:/apache-tomcat-6.0.43/webapps/shop1/indexDir"></property>
</bean>

配置类:

public class Configuration {

private Analyzer analyzer= null ;

private Directory directory =null;

public Analyzer getAnalyzer() {
    return analyzer;
}

public Directory getDirectory() {
    return directory;
}

private String dirPath = null;

public void setDirPath(String dirPath) {
    this.dirPath = dirPath;
}

public void init(){
    try {
        analyzer = new IKAnalyzer(true);
        directory = FSDirectory.open(new File(dirPath));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
}

测试代码是:

    @Test
public void testConfiguratin() {
    System.out.println("Analyzer:"+configuration.getAnalyzer());
    System.out.println("configuration"+configuration.getDirectory());
}

为什么值为null,如何解决警告消息?

1 个答案:

答案 0 :(得分:1)

该消息告诉您,项目中没有Ehcache框架的配置文件。因此,它从jar文件加载默认配置。您可以从项目中删除jar,也可以在类路径中创建一个ehcache.xml(&#34; src&#34;,&#34; src / main / java /&#34;)并添加如下内容:< / p>

<?xml version="1.0" encoding="UTF-8"?>
<ehcache>

   <diskStore path="java.io.tmpdir"/>

   <defaultCache
        maxElementsInMemory="50000"
        eternal="false"
        timeToIdleSeconds="60"
        timeToLiveSeconds="60"
        overflowToDisk="false"
        diskPersistent="false"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU"
   />
</ehcache>

由于您已经在使用Spring,因此很容易在您的应用中使用该缓存see here