小编Say*_*yay的帖子

Spring Data无法在postgresql中使用UUID获取记录

我使用Spring数据来管理REST API.我的postgresql数据库中的所有表都有一个UUID类型的主键.我能够保留这些数据但无法获取它.下面是我正在使用的代码和我面临的问题.

MyTableParent.java

@MappedSuperclass
public class MyTableParent {
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(
            name = "uuid",
            strategy = "com.mypackage.UUIDGenerator",
            parameters = {
                    @Parameter(
                            name = UUID_NAMESPACE,
                            value = "something"
                    )
            }
    )
    private UUID id;
    // Constructor getter setter
}
Run Code Online (Sandbox Code Playgroud)

MyTable.java

@Entity
@Table(name = "my_table")
public class MyTable extends MyTableParent {
    private String name;
    // constructor getter setter
}
Run Code Online (Sandbox Code Playgroud)

这是我的表的服务类

TableService.java

@Service("tableservice")
public class TableService {
    private TableRepository tableRepository;

    public TableService(TableRepository tableRepository) {
        this.tableRepository = tableRepository;
    }

    public List<MyTable> read(MultiValueMap<String, …
Run Code Online (Sandbox Code Playgroud)

java postgresql spring-data-jpa

6
推荐指数
2
解决办法
2846
查看次数

在findOneAndUpdate()的pre钩子上修改mongoose文档

我有一个mongoose架构

var schema = new Schema({
    id:Number
    updated_at:Date
});
Run Code Online (Sandbox Code Playgroud)

我正在使用findOneAndUpdate()这样更新此模型

model.findOneAndUpdate(
    { id: json.id },
    json,
    {
        upsert: true,
        runValidators: true
    })
    .then(() => {
        recordsUpdated++;
    })
    .catch((err) => {
        this.emit('error', err);
    });
Run Code Online (Sandbox Code Playgroud)

传入的值json不正确,我需要对其进行一些修改.我正在寻找一个预钩子进行修改.我试过了

faction.pre('findOneAndUpdate', function (next) {
   this.update({ $set: { updated_at: this.getUpdate().updated_at * 1000 } });
   next();
});
Run Code Online (Sandbox Code Playgroud)

简而言之,我想在更新数据库之前将时间戳(以秒为单位)转换为毫秒,但这不起作用.

mongoose node.js

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

Spring 中 ApplicationContext.getBean() 的替代方案

我在我的应用程序中使用 SpringBoot,并且目前正在使用applicationContext.getBean(beanName,beanClass)它在对它执行操作之前获取我的 bean。我在几个问题中看到不鼓励使用getBean(). 由于我对 Spring 非常陌生,因此我不了解所有最佳实践并且很矛盾。上述链接问题中提出的解决方案可能不适用于我的用例。我应该如何处理这个问题?

@RestController
@RequestMapping("/api")
public class APIHandler {
    @Value("${fromConfig}")
    String fromConfig;

    private ApplicationContext applicationContext;

    public Bot(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @PostMapping(value = "")
    public ResponseEntity post(@RequestBody HandlingClass requestBody) {
        SomeInterface someInterface = applicationContext.getBean(fromConfig, SomeInterface.class);
        someInterface.doSomething();
    }
}
Run Code Online (Sandbox Code Playgroud)

我有一个名为SomeInterface定义的接口,如下所示:

public interface SomeInterface {

    void doSomething();
}
Run Code Online (Sandbox Code Playgroud)

我有 2 个类实现了这个接口,称为UseClass1UseClass2。我的配置文件存储了一个带有类的 bean 名称的字符串,我需要在运行时知道它并调用该方法的适当实现。

任何方向将不胜感激。

java spring spring-boot

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

在 Kubernetes 上使用 Quartz 调度程序运行 Spring Boot 项目

我正在开发一个 Spring Boot 项目,该项目具有使用 Quartz 的调度程序服务。此调度程序服务通过调用单独的微服务来运行特定的调度或 cron 作业。

现在我打算在 kubernetes 上部署我的微服务,我想确保我的调度程序服务也是集群的。我注意到 Quartz支持使用 JDBC-JobStore 进行集群,但我不完全确定是否可以使用 kubernetes 部署这样的场景。如果我有 3 个使用 kubernetes 管理和扩展的 Scheduler 服务 pod,它会起作用吗?

quartz-scheduler spring-boot kubernetes

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

无法通过 Docker 将基于 nuxt 的 Express 服务器端口转发到主机

我正在使用 Docker for Windows(Windows 10 是 2004 年的,所以我有 WSL2),并且我正在尝试容器化 Nuxt 应用程序。该应用程序在我的本地系统上运行良好,在创建 Dockerfile 并构建它之后,我无法将其转发到我的主机系统上。然而,当尝试使用来自https://github.com/BretFisher/docker-mastery-for-nodejs/tree/master/ultimate-node-dockerfile的示例应用程序时(test应该使用该文件夹中的 Dockerfile ),我可以访问相同的。

\n

如果我exec进入正在运行的容器,我能够获得运行时的输出curl http://localhost:3000,所以一切都应该很好。

\n

我的 Dockerfile 看起来像

\n
FROM node:12.18.3-buster-slim\nLABEL org.opencontainers.image.authors=sayak@redacted.com\nEXPOSE 3000\nWORKDIR /app\nRUN chown -R node:node /app\nCOPY --chown=node:node package*.json ./\nENV NODE_ENV=development\nRUN apt-get update -qq && apt-get install -qy \\\n    ca-certificates \\\n    bzip2 \\\n    curl \\\n    libfontconfig \\\n    --no-install-recommends\nUSER node\nRUN npm config list\nRUN npm ci \\\n    && npm cache clean --force\nENV PATH=/app/node_modules/.bin:$PATH\nCOPY --chown=node:node . .\nRUN nuxt build\nENV NODE_ENV=production\nCMD …
Run Code Online (Sandbox Code Playgroud)

node.js docker dockerfile

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