小编Thy*_*els的帖子

Spring Redis Delete不会删除密钥

我试图删除一个redis密钥但由于某种原因它不是删除但也没有抛出异常.这是我要删除的代码:

import com.example.service.CustomerService;
import com.example.model.Customer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.*;

@Service
public class RedisCustomerService implements CustomerService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate; 

    private String uniqueIdKey = "customerId";

    private BigInteger uniqueId() {
        long uniqueId = this.redisTemplate.opsForValue().increment(uniqueIdKey, 1);
        return BigInteger.valueOf(uniqueId);
    }

    private String lastNameKey(BigInteger id) {
        return "customer:ln:" + id;
    }

    private String firstNameKey(BigInteger id) {
        return "customer:fn:" + id;
    }

    @Override
    public void deleteCustomer(BigInteger id) {
        redisTemplate.opsForValue().getOperations().delete(String.valueOf(id));
    }
}
Run Code Online (Sandbox Code Playgroud)

spring redis

8
推荐指数
2
解决办法
1万
查看次数

MongoDB没有找到能够从类型org.bson.types.ObjectId转换为java.lang.Long类型的转换器

我为Postgres和MongoDB使用的客户提供了以下模型.它适用于Postgres,但是当我想列出MongoDB中的所有客户时,我收到此错误:

org.springframework.core.convert.ConverterNotFoundException:找不到能够从类型org.bson.types.ObjectId转换为java.lang.Long类型的转换器

这是我的模型类:

package com.example.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@XmlRootElement(name = "customer")
@Table(name = "customer")
public class Customer implements java.io.Serializable {

    private static final long serialVersionUID = 1L;
    private Long id;
    private String firstName;
    private String lastName;

    public Customer() {
    }

    public Customer(String fn, String ln) {
        this.firstName = fn;
        this.lastName = ln;
    }

    public Customer(Long id, String firstName, String lastName) {
        this.id = id; …
Run Code Online (Sandbox Code Playgroud)

spring mongodb

1
推荐指数
2
解决办法
2万
查看次数

弹簧启动执行器健康终点

我已经创建了一个像这样的PostgreSQL运行状况指示器:

@Component
public class PostgresHealthIndicator extends AbstractHealthIndicator {

    @Autowired
    DataSource postgresDataSource;

    public DataSourceHealthIndicator dbHealthIndicator() {
        DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(postgresDataSource);
        return indicator;
    }

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        Health h = dbHealthIndicator().health();
        Status status = h.getStatus();
        if (status != null && "DOWN".equals(status.getCode())) {
            builder.down();
        } else {
            builder.up();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的Application.java中,我正在为此组件扫描此包:

@ComponentScan({"com.bp.health"})
Run Code Online (Sandbox Code Playgroud)

在我的application.properties中,我有以下设置:

endpoints.health.sensitive=false
endpoints.health.id=health
endpoints.health.enabled=true
Run Code Online (Sandbox Code Playgroud)

当我点击{url}/health时,我看到:

{ "地位": "DOWN"}

我需要做什么才能显示自定义健康指标?

spring spring-boot spring-boot-actuator actuator

1
推荐指数
1
解决办法
1万
查看次数