我正在尝试将spring boot与redis混合在一起。这些是依赖:https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/1.5.10.RELEASE https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis/2.0.4.RELEASE
但是,当我实现redis bean时,我收到一个错误:
java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;
这两个依赖项是否可能不混合?
编辑:添加代码
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
@Configuration
public class RedisConfiguration {
@Value("${redis.host}")
private String host;
@Value("${redis.port}")
private int port;
@Value("${redis.pw}")
private String password;
@Value("${redis.user}")
private String user;
@Bean
JedisConnectionFactory jedisConnectionFactory() {
System.out.println("setting up port: " + this.port);
JedisConnectionFactory jedisConFactory
= new JedisConnectionFactory();
jedisConFactory.setHostName(this.host);
jedisConFactory.setClientName(this.user);
jedisConFactory.setPort(this.port);
jedisConFactory.setPassword(this.password);
return jedisConFactory;
}
@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
}
Pom.hml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<type>jar</type>
</dependency>
</dependencies>
dep树:
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.5.10.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.5.10.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.10.RELEASE:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] | | | \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.17:compile
[INFO] | \- org.springframework.boot:spring-boot-actuator:jar:1.5.10.RELEASE:compile
[INFO] | \- org.springframework:spring-context:jar:4.3.14.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.10.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.10.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.27:compile
[INFO] | | | \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.27:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.27:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.27:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
[INFO] | +- org.springframework:spring-web:jar:4.3.14.RELEASE:compile
[INFO] | | \- org.springframework:spring-beans:jar:4.3.14.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.3.14.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.3.14.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jersey:jar:1.5.10.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:1.5.10.RELEASE:compile
[INFO] | +- org.glassfish.jersey.core:jersey-server:jar:2.25.1:compile
[INFO] | | +- org.glassfish.jersey.core:jersey-common:jar:2.25.1:compile
[INFO] | | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.25.1:compile
[INFO] | | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] | | +- org.glassfish.jersey.core:jersey-client:jar:2.25.1:compile
[INFO] | | +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO] | | +- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.25.1:compile
[INFO] | | +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] | | +- org.glassfish.hk2:hk2-api:jar:2.5.0-b32:compile
[INFO] | | | +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b32:compile
[INFO] | | | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b32:compile
[INFO] | | +- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b32:compile
[INFO] | | \- org.glassfish.hk2:hk2-locator:jar:2.5.0-b32:compile
[INFO] | +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.25.1:compile
[INFO] | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.25.1:compile
[INFO] | +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.25.1:compile
[INFO] | +- org.glassfish.jersey.ext:jersey-spring3:jar:2.25.1:compile
[INFO] | | +- org.glassfish.hk2:hk2:jar:2.5.0-b32:compile
[INFO] | | | +- org.glassfish.hk2:config-types:jar:2.5.0-b32:compile
[INFO] | | | +- org.glassfish.hk2:hk2-core:jar:2.5.0-b32:compile
[INFO] | | | +- org.glassfish.hk2:hk2-config:jar:2.5.0-b32:compile
[INFO] | | | +- org.glassfish.hk2:hk2-runlevel:jar:2.5.0-b32:compile
[INFO] | | | \- org.glassfish.hk2:class-model:jar:2.5.0-b32:compile
[INFO] | | | \- org.glassfish.hk2.external:asm-all-repackaged:jar:2.5.0-b32:compile
[INFO] | | \- org.glassfish.hk2:spring-bridge:jar:2.5.0-b32:compile
[INFO] | \- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.25.1:compile
[INFO] | +- org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.25.1:compile
[INFO] | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.8.10:compile
[INFO] | \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.8.10:compile
[INFO] | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.8.10:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.5.10.RELEASE:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:1.5.10.RELEASE:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.10.RELEASE:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] | | \- net.minidev:json-smart:jar:2.2.1:test
[INFO] | | \- net.minidev:accessors-smart:jar:1.1:test
[INFO] | | \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] | +- junit:junit:jar:4.12:test
[INFO] | +- org.assertj:assertj-core:jar:2.6.0:test
[INFO] | +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | | \- org.objenesis:objenesis:jar:2.1:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] | +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO] | | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] | +- org.springframework:spring-core:jar:4.3.14.RELEASE:compile
[INFO] | \- org.springframework:spring-test:jar:4.3.14.RELEASE:test
[INFO] +- com.zaxxer:HikariCP:jar:2.5.1:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.webjars:webjars-locator:jar:0.32-1:compile
[INFO] | \- org.webjars:webjars-locator-core:jar:0.32:compile
[INFO] | \- org.apache.commons:commons-compress:jar:1.9:compile
[INFO] +- org.webjars:bootstrap:jar:4.0.0:compile
[INFO] | +- org.webjars:jquery:jar:3.0.0:compile
[INFO] | \- org.webjars.npm:popper.js:jar:1.11.1:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.5.10.RELEASE:runtime
[INFO] | +- org.springframework.boot:spring-boot:jar:1.5.10.RELEASE:compile
[INFO] | \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.10.RELEASE:compile
[INFO] +- io.swagger:swagger-jersey2-jaxrs:jar:1.5.13:compile
[INFO] | \- org.glassfish.jersey.media:jersey-media-multipart:jar:2.25.1:compile
[INFO] | \- org.jvnet.mimepull:mimepull:jar:1.9.6:compile
[INFO] +- io.swagger:swagger-jaxrs:jar:1.5.13:compile
[INFO] | +- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO] | +- org.reflections:reflections:jar:0.9.10:compile
[INFO] | | +- org.javassist:javassist:jar:3.21.0-GA:compile
[INFO] | | \- com.google.code.findbugs:annotations:jar:2.0.1:compile
[INFO] | \- com.google.guava:guava:jar:20.0:compile
[INFO] +- io.swagger:swagger-models:jar:1.5.13:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] +- io.swagger:swagger-core:jar:1.5.13:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.2.1:compile
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.10:compile
[INFO] | \- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] +- io.swagger:swagger-annotations:jar:1.5.13:compile
[INFO] +- org.projectlombok:lombok:jar:1.16.16:provided
[INFO] +- org.springframework.data:spring-data-redis:jar:2.0.4.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-keyvalue:jar:1.2.10.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:1.13.10.RELEASE:compile
[INFO] | | \- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] | +- org.springframework:spring-tx:jar:4.3.14.RELEASE:compile
[INFO] | +- org.springframework:spring-oxm:jar:4.3.14.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.3.14.RELEASE:compile
[INFO] | \- org.springframework:spring-context-support:jar:4.3.14.RELEASE:compile
[INFO] \- redis.clients:jedis:jar:2.9.0:compile
[INFO] \- org.apache.commons:commons-pool2:jar:2.4.3:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
Spring Boot 1.x和Spring Data 2.x不兼容。保持完全在1.x线上,或升级到计划发布today的Spring Boot 2.0。
Spring数据redis确实带有默认的redis客户端版本。检查你的mvn依赖树,看看是否有多个redis版本。如果是,请尝试排除一个。