如何将redis和couchbase连接到spring应用程序。我得到这个错误 Parameter 0 of method couchbaseMappingContext in org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration required a single bean, but 2 were found: - couchbaseCustomConversions: defined by method 'customConversions' in class path resource [{classPath}/chat/config/CouchbaseConfiguration.class] - redisCustomConversions: defined in null
我只需要redis“看”一个包,其他的只需要连接couchbase。
redis配置
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
MappingJackson2HttpMessageConverter converter =
new MappingJackson2HttpMessageConverter(mapper);
return converter;
}
@Bean
public RedisTemplate<Long, ?> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<Long, ?> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
// Add some specific configuration here. Key serializers, etc.
return template;
}
沙发床配置
@EnableCouchbaseRepositories
@Configuration
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
@Value("${spring.data.couchbase.bucket-name}")
private String bucketName;
@Value("${spring.couchbase.username}")
private String username;
@Value("${spring.couchbase.password}")
private String password;
@Value("${spring.couchbase.connection-string}")
private String connectionString;
@Override
public String getConnectionString() {
return this.connectionString;
}
@Override
public String getUserName() {
return this.username;
}
@Override
public String getPassword() {
return this.password;
}
@Override
public String getBucketName() {
return this.bucketName;
}
}
当我第一次在终端上启动我的应用程序时,有这样一个信息:springdataredis-无法安全地识别存储库候选接口的存储分配
1条答案
按热度按时间mm5n2pyu1#
为了解决使用customconversions bean时的模糊性,我们可以告诉couchbase配置类如何创建customconversions bean。将下面的代码添加到扩展abstractcouchbaseconfiguration的类应该可以解决这个问题