java - 无法找到 org.springframework.format.datetime.standard.DateTimeConverters

标签 java spring maven converters

有一个 Spring 类,org.springframework.format.datetime.standard.DateTimeConverters,其中包含一些有用的转换器,但我找不到。它记录在4.1.0.RC1_to_4.1.0.RC2 中javadoc 但不在 4.1.0.RELEASE 中。请注意 javadoc 中的 @UsesJava8 注释。当然,我使用的是 Java 8,因为我需要在新类型之间进行转换。

该类的源代码位于 GitHub使用 4.1 标签,然后我使用以下 xml 通过 Maven 将项目添加到我的 pom.xml 中。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.2.1.RELEASE</version>
</dependency>

转换器是否已移至另一个包?我在哪里可以找到它们?

最佳答案

版本 4.2.1 中的 spring-context Artifact 包含 DateTimeConverters 类,如 GitHub repo 中所示。 .

但请注意,它是一个包类,它不是公共(public) API 的一部分,这就是该类在在线 Javadoc 中不可见的原因。 javadoc默认情况下不生成包类的HTML页面; quoting its reference (强调我的):

The javadoc command parses the declarations and documentation comments in a set of Java source files and produces a corresponding set of HTML pages that describe (by default) the public and protected classes, nested classes (but not anonymous inner classes), interfaces, constructors, methods, and fields.

如果您真的很好奇,您可以通过查看 build.gradle 看到 Spring 在 Javadoc 生成期间保留默认值。 .

如果您使用的是 Java 8,Spring 会自动使用以下 XML 声明注册这些转换器:

<mvc:annotation-driven conversion-service="conversionService"/>

<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />

关于java - 无法找到 org.springframework.format.datetime.standard.DateTimeConverters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32507470/

相关文章:

java - 如何避免一个测试类中的模拟注入(inject)对不同类的影响?

maven - Intellij : web app is fine at work but stops working at home (via VPN)

java - 当前请求不是多部分请求 - Spring MVC

java - 使用 long 类型的键和 long 类型的 hashset 值创建一个 hashmap

java - 类型级别的 Spring Security @PreAuthorize 不能在方法级别上覆盖

java - 用于检测开头或结尾的点的正则表达式

java - Jackson 忽略抽象类的 xml 根元素

spring-boot v2 执行器选择器

java - 在子类中覆盖@jsonIgnore

java - 使用 Maven 将资源文件夹下的文件添加到 zip