Unable to find org.springframework.format.datetime

2019-07-13 14:35发布

问题:

There is a Spring class, org.springframework.format.datetime.standard.DateTimeConverters, with some useful converters, that I am not able to find. It is documented in the 4.1.0.RC1_to_4.1.0.RC2 javadoc but not in the 4.1.0.RELEASE. Note the @UsesJava8 annotation in the javadoc. Of course I am using Java 8 as I need to convert between the new types.

The class has its source code in GitHub with the 4.1 tag and I add the project by Maven using the following xml to my pom.xml.

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

Were the converters moved to another package? Where can I find them?

回答1:

The spring-context artifact in version 4.2.1 contains the DateTimeConverters class, as can be seen in the GitHub repo.

Note however that it is a package class, it is not part of the public API and that's why this class is not visible in the online Javadoc. javadoc, by default, does not generate HTML pages for package classes; quoting its reference (emphasis mine):

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.

And if you're really curious, you can see that Spring keeps the default values during Javadoc generation, by looking at their build.gradle.

If you're using Java 8, Spring automatically registers those converters with the following XML declaration:

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

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