我试图在spring-boot应用程序中使用spring-data-redis来处理redis.我创建JedisConnectionFactory如下:
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
configuration.setHostName("localhost");
configuration.setPort(6379);
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(configuration);
Run Code Online (Sandbox Code Playgroud)
它抛出了异常:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;
at org.springframework.data.redis.repository.configuration.RedisRepositoryConfigurationExtension.registerBeansForRoot(RedisRepositoryConfigurationExtension.java:88)
at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:118)
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:59)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:352)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:143)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:336)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:246)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at com.test.redis.RedisTesterApplication.main(RedisTesterApplication.java:11)
Run Code Online (Sandbox Code Playgroud)
我的build.gradle:
dependencies {
compile('org.springframework.data:spring-data-redis:2.0.2.RELEASE')
compile('redis.clients:jedis:2.9.0')
compile('org.json:json:20160810')
compile('org.springframework.boot:spring-boot-starter:1.4.2.RELEASE')
compile("org.springframework:spring-web")
compile('org.slf4j:slf4j-api:+')
}
Run Code Online (Sandbox Code Playgroud)
是因为spring-boot和spring-data-redis的不兼容的依赖版本?我怎么知道要使用哪个版本?
特别是在readUnshared()方法的背景下,ObjectInputStream"反向引用"是什么意思?
我在这里遇到了这个词
如果调用readUnshared反序列化反向引用(先前已写入流的对象的流表示),则抛出ObjectStreamException.
参考:https://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#readUnshared()
我有这样的事情:
public interface SomeInterface {
public String someMethod(String someArg1, String someArg2);
}
public class SomeInterfaceImpl {
@Override
public String someMethod(String someArg1, String someArg2) {
String response;
// a REST API call which fetches response (need to mock this)
return response;
}
}
public class SomeClass {
public int execute() {
int returnValue;
// some code
SomeInterface someInterface = new SomeInterfaceImpl();
String response = someInterface.someMethod("some1", "some2");
// some code
return returnValue;
}
}
Run Code Online (Sandbox Code Playgroud)
我想execute()在SomeClass使用 JUnit 时测试该方法。由于someMethod(String …
我试图实现与此相同的事情:如何使用Spring RestTemplate表示为JSON的查询参数?,将JSON字符串作为URL参数发送restTemplate.exchange().
接受的答案提到将JSON对象作为请求参数发送通常不是一个好主意,因为您可能会遇到JSON中的大括号问题.这正是我尝试对API进行GET调用时发生的事情.由于这是来自另一个系统的API,我不能要求他们更改格式,并且必须调用GET端点,将JSON作为参数传递.我怎样才能实现这一目标restTemplate.exchange()?
注意:提到的相关问题没有指导如何克服这个问题,我没有足够的声誉来评论它,以询问作者的答案.
java ×4
jedis ×1
json ×1
junit ×1
mockito ×1
powermockito ×1
resttemplate ×1
spring ×1
spring-boot ×1
unit-testing ×1