小编Joe*_*oel的帖子

如何为 MSSQL 日期配置 spring.data.convert.CustomConversion

最近我注意到我们的 spring-boot 服务正在记录来自org.springframework.data.convert.CustomConversions.

消息是这样的:

注册从 microsoft.sql.DateTimeOffset 类到 java.time.OffsetDateTime 类的转换器作为读取转换器,尽管它不会从存储支持的类型进行转换!您可能需要检查转换器实现中的注释设置。

相关的依赖关系pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.3</version>
</parent>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>9.4.1.jre16</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我当然可以通过将日志级别设置为此处提出的类似问题的error答案所建议的方式来抑制警告的记录,例如这样这样

实体 POJO 的日期/日期时间字段为java.sql.Timestampjava.util.Date,SQL Server 表具有类型为datedatetime2和 的列datetime。从 POJO 到 SQL 的映射是由org.springframework.data.repository.*/org.springframework.data.jdbc.repository.*类完成的。

我想知道如何正确配置,CustomConversions以便在可能的情况下完全避免警告。

sql-server datetime datetime2 spring-data

7
推荐指数
0
解决办法
1142
查看次数

如何使用`with-redefs`总是抛出函数异常

我想对代码的异常处理部分进行单元测试。为了做到这一点,我使用with-redefs了重新绑定可以抛出异常的API来在测试期间抛出异常。我的测试功能看起来像这样

(deftest exception-handling
  (testing "Map exception to Ring-response map"
    (with-redefs [clj-http/get
                  (constantly (throw (ex-info "unexpected error" {:cause "A terrible calamity"})))]
      (is (= 500
        (:status
          (some-function-calling-http-get arg))))
    )
  )
)
Run Code Online (Sandbox Code Playgroud)

运行会lein test导致错误消息:

    ERROR in (exception-handling) (core.clj:4593)
Uncaught exception, not in assertion.
expected: nil
  actual: clojure.lang.ExceptionInfo: unexpected error
 at clojure.core$ex_info.invoke (core.clj:4593)
Run Code Online (Sandbox Code Playgroud)

使用(constantly (throw...in with-redefs或仅断言抛出了一个异常thrown?也会导致相同的错误。

本质上,我正在寻找的宏版本constantly

unit-testing clojure

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