实例化CommonsHttpSolrServer时出现异常

时间:2012-09-19 08:58:26

标签: java maven solr solrj

我有一个这样的类(它是eclipse中的一个java类,在Maven项目下):

public class SolrJ
{
    public static void main( String[] args )
    {
        String url = "http://localhost:8983/solr";
        try {
            SolrServer server = new CommonsHttpSolrServer(url);
            server.deleteByQuery( "*:*" );
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (SolrServerException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

运行此课程后,我遇到以下异常:

Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
    at org.slf4j.LoggerFactory.staticInitialize(LoggerFactory.java:83)
    at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:73)
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.<clinit>(CommonsHttpSolrServer.java:77)
    at ultimo.solrJ.SolrJ.main(SolrJ.java:19)

我的pom.xml看起来像这样:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <artifactId>solr-solrj</artifactId>
        <groupId>org.apache.solr</groupId>
        <version>1.4.0</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <artifactId>solr-core</artifactId>
        <groupId>org.apache.solr</groupId>
        <version>1.4.0</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.5.6</version>
    </dependency>

任何人都可以帮助解决我的问题吗?我已经通过互联网进行了分析,我找不到任何方法来解决我的问题。

1 个答案:

答案 0 :(得分:1)