spring-mvc CassandraTemplate NoClassDefFoundError

时间:2015-10-19 16:59:33

标签: spring-mvc cassandra spring-data-cassandra

使用spring-data-cassandra时,我的pom.xml遇到了一些麻烦。

我的pom.xml看起来像 -

<properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

        <!-- Cassandra -->

        <dependency>
            <groupId>org.apache.cassandra</groupId>
            <artifactId>cassandra-all</artifactId>
            <version>2.2.3</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-cassandra</artifactId>
            <version>1.3.0.RELEASE</version>
        </dependency>

我的主控制器类如下所示 -

public String insertEmp(Locale locale, Model model, @ModelAttribute Employee emp) {
    logger.info("Create method in home controller", locale);

    String serverIP = "127.0.0.1";
    String keyspace = "jetset";

    Cluster cluster = Cluster.builder()
      .addContactPoints(serverIP)
      .build();

    Session session = cluster.connect(keyspace);

    CassandraOperations cassandraTemplate = new CassandraTemplate(session);

    model.addAttribute("serverTime", "Test" );
    //employeeService.createEmployee(emp);
    cassandraTemplate.insert(emp);

    return "admin/index";
}

现在,当我运行程序时,我遇到了错误 -

Caused by: java.lang.NoClassDefFoundError: org/springframework/core/DefaultParameterNameDiscoverer
    at org.springframework.data.mapping.model.PreferredConstructorDiscoverer.<init>(PreferredConstructorDiscoverer.java:38) ~[spring-data-commons-1.11.0.RELEASE.jar:na]
    at org.springframework.data.mapping.model.BasicPersistentEntity.<init>(BasicPersistentEntity.java:92) ~[spring-data-commons-1.11.0.RELEASE.jar:na]
    at org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity.<init>(BasicCassandraPersistentEntity.java:83) ~[spring-data-cassandra-1.3.0.RELEASE.jar:na]
    at org.springframework.data.cassandra.mapping.BasicCassandraMappingContext.createPersistentEntity(BasicCassandraMappingContext.java:123) ~[spring-data-cassandra-1.3.0.RELEASE.jar:na]
    at org.springframework.data.cassandra.mapping.BasicCassandraMappingContext.createPersistentEntity(BasicCassandraMappingContext.java:54) ~[spring-data-cassandra-1.3.0.RELEASE.jar:na]
    at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:299) ~[spring-data-commons-1.11.0.RELEASE.jar:na]
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:179) ~[spring-data-commons-1.11.0.RELEASE.jar:na]
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:139) ~[spring-data-commons-1.11.0.RELEASE.jar:na]
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:66) ~[spring-data-commons-1.11.0.RELEASE.jar:na]
    at org.springframework.data.cassandra.core.CassandraTemplate.getTableName(CassandraTemplate.java:217) ~[spring-data-cassandra-1.3.0.RELEASE.jar:na]
    at org.springframework.data.cassandra.core.CassandraTemplate.doInsert(CassandraTemplate.java:641) ~[spring-data-cassandra-1.3.0.RELEASE.jar:na]
    at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:237) ~[spring-data-cassandra-1.3.0.RELEASE.jar:na]
    at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:232) ~[spring-data-cassandra-1.3.0.RELEASE.jar:na]
    at org.jetset.estate.HomeController.insertEmp(HomeController.java:91) ~[classes/:na]

这看起来像是一个pom问题,但我无法弄明白。

请建议。

感谢。

AJ

1 个答案:

答案 0 :(得分:0)

好的,修好了。

我用spring-data-cassandra选择了错误的弹簧分布。

切换到弹簧3.2.8和cassandra到1.0.0并且问题已修复。

希望这对其他人也有帮助。