代码之家  ›  专栏  ›  技术社区  ›  João Menighin

joda.time.datetime.toLocalateTime()NoSuchMethodError

  •  1
  • João Menighin  · 技术社区  · 6 年前

    我正在尝试在我的Spring引导配置中使用joda localdatetime和jpa。 为此,我读过 this 教程,我可以使用 DateTime 完全没有问题。 当我尝试使用时,问题就出现了 LocalDateTime . 出于某种原因,当从我的数据库中提取实体时,会引发一个错误:

    java.lang.NoSuchMethodError: org.joda.time.DateTime.toLocalDateTime()Lorg/joda/time/LocalDateTime;
    

    enter image description here

    我已经检查过了方法 toLocalDateTime 是否存在于Joda时代:

    enter image description here

    那么,怎么回事?D:

    我也试过设置 @Type 正如本教程所建议的,但得到了相同的结果:

    @Column(name = "myLocalDateTime")
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime localDateTime;
    

    要从数据库中检索数据,我只需使用 spring-data 储存库。

    以下是关于我的环境的一些信息:

    渐变相关性:

    // ...
    compile 'org.hibernate:hibernate-core:5.1.16.Final'
    compile 'org.hibernate:hibernate-validator:5.2.3.Final'
    compile 'org.hibernate:hibernate-entitymanager:5.1.0.Final'
    compile 'joda-time:joda-time'
    compile group: 'org.jadira.usertype', name: 'usertype.core', version: '5.0.0.GA'
    

    应用程序属性:

    # ...
    spring.jpa.properties.jadira.usertype.autoRegisterUserTypes = true
    

    我在Java 7上运行了Spring Bug 1.5.15.RELEASE

    任何帮助都非常感谢。

    编辑

    有趣的是,在我的数据库中用一个localdatetime字段持久化一条记录,效果很好…:

    以下是我的项目中的libs列表:

    Gradle: antlr:antlr:2.7.7
    Gradle: aopalliance:aopalliance:1.0
    Gradle: ch.qos.logback:logback-classic:1.1.11
    Gradle: ch.qos.logback:logback-core:1.1.11
    Gradle: com.fasterxml.jackson.core:jackson-annotations:2.8.0
    Gradle: com.fasterxml.jackson.core:jackson-core:2.8.11
    Gradle: com.fasterxml.jackson.core:jackson-databind:2.8.11.2
    Gradle: com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.11
    Gradle: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.8.11
    Gradle: com.fasterxml.woodstox:woodstox-core:5.0.3
    Gradle: com.fasterxml:classmate:1.3.4
    Gradle: com.github.virtuald:curvesapi:1.04
    Gradle: com.google.code.findbugs:jsr305:1.3.9
    Gradle: com.google.guava:guava:19.0
    Gradle: com.infradna.tool:bridge-method-annotation:1.13
    Gradle: com.jayway.jsonpath:json-path:2.2.0
    Gradle: com.mysema.commons:mysema-commons-lang:0.2.4
    Gradle: com.querydsl:querydsl-core:4.1.4
    Gradle: com.querydsl:querydsl-jpa:4.1.4
    Gradle: com.sun.istack:istack-commons-runtime:2.16
    Gradle: com.sun.xml.bind:jaxb-core:2.2.7
    Gradle: com.sun.xml.bind:jaxb-impl:2.2.7
    Gradle: com.sun.xml.fastinfoset:FastInfoset:1.2.12
    Gradle: com.vaadin.external.google:android-json:0.0.20131108.vaadin1
    Gradle: commons-beanutils:commons-beanutils:1.9.3
    Gradle: commons-codec:commons-codec:1.10
    Gradle: commons-collections:commons-collections:3.2.2
    Gradle: dom4j:dom4j:1.6.1
    Gradle: io.netty:netty-all:4.1.5.Final
    Gradle: javax.inject:javax.inject:1
    Gradle: javax.servlet:javax.servlet-api:3.1.0
    Gradle: javax.transaction:javax.transaction-api:1.2
    Gradle: javax.validation:validation-api:1.1.0.Final
    Gradle: javax.xml.bind:jaxb-api:2.2.7
    Gradle: javax.xml.bind:jsr173_api:1.0
    Gradle: javax.xml.stream:stax-api:1.0-2
    Gradle: joda-time:joda-time:2.9.9
    Gradle: junit:junit:4.12
    Gradle: net.minidev:accessors-smart:1.1
    Gradle: net.minidev:json-smart:2.2.1
    Gradle: org.apache.activemq:artemis-commons:1.5.6
    Gradle: org.apache.activemq:artemis-core-client:1.5.6
    Gradle: org.apache.activemq:artemis-jms-client:1.5.6
    Gradle: org.apache.activemq:artemis-selector:1.5.6
    Gradle: org.apache.commons:commons-collections4:4.1
    Gradle: org.apache.commons:commons-lang3:3.4
    Gradle: org.apache.geronimo.specs:geronimo-jms_2.0_spec:1.0-alpha-2
    Gradle: org.apache.geronimo.specs:geronimo-json_1.0_spec:1.0-alpha-1
    Gradle: org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1
    Gradle: org.apache.johnzon:johnzon-core:0.9.5
    Gradle: org.apache.poi:poi-ooxml-schemas:3.17
    Gradle: org.apache.poi:poi-ooxml:3.17
    Gradle: org.apache.poi:poi:3.17
    Gradle: org.apache.santuario:xmlsec:2.0.7
    Gradle: org.apache.xmlbeans:xmlbeans:2.6.0
    Gradle: org.aspectj:aspectjweaver:1.8.13
    Gradle: org.assertj:assertj-core:2.6.0
    Gradle: org.atteo:evo-inflector:1.2.2
    Gradle: org.codehaus.woodstox:stax2-api:3.1.4
    Gradle: org.codehaus.woodstox:woodstox-core-asl:4.4.1
    Gradle: org.hamcrest:hamcrest-core:1.3
    Gradle: org.hamcrest:hamcrest-library:1.3
    Gradle: org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
    Gradle: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
    Gradle: org.hibernate:hibernate-core:5.1.16.Final
    Gradle: org.hibernate:hibernate-entitymanager:5.1.0.Final
    Gradle: org.hibernate:hibernate-validator:5.2.3.Final
    Gradle: org.jadira.usertype:usertype.core:5.0.0.GA
    Gradle: org.jadira.usertype:usertype.spi:5.0.0.GA
    Gradle: org.javassist:javassist:3.21.0-GA
    Gradle: org.jboss.logging:jboss-logging:3.3.2.Final
    Gradle: org.jboss:jandex:2.0.3.Final
    Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.2.70
    Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.2.70
    Gradle: org.jetbrains:annotations:13.0
    Gradle: org.jgroups:jgroups:3.6.9.Final
    Gradle: org.mockito:mockito-core:1.10.19
    Gradle: org.objenesis:objenesis:2.1
    Gradle: org.ow2.asm:asm:5.0.3
    Gradle: org.skyscreamer:jsonassert:1.4.0
    Gradle: org.slf4j:jcl-over-slf4j:1.7.25
    Gradle: org.slf4j:jul-to-slf4j:1.7.25
    Gradle: org.slf4j:log4j-over-slf4j:1.7.25
    Gradle: org.slf4j:slf4j-api:1.7.25
    Gradle: org.springframework.boot:spring-boot-autoconfigure:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-devtools:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-aop:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-artemis:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-data-jpa:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-data-rest:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-jdbc:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-logging:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-security:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-test:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-web-services:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter-web:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-starter:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-test-autoconfigure:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot-test:1.5.15.RELEASE
    Gradle: org.springframework.boot:spring-boot:1.5.15.RELEASE
    Gradle: org.springframework.data:spring-data-commons:1.13.14.RELEASE
    Gradle: org.springframework.data:spring-data-jpa:1.11.14.RELEASE
    Gradle: org.springframework.data:spring-data-rest-core:2.6.14.RELEASE
    Gradle: org.springframework.data:spring-data-rest-webmvc:2.6.14.RELEASE
    Gradle: org.springframework.hateoas:spring-hateoas:0.23.0.RELEASE
    Gradle: org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE
    Gradle: org.springframework.security:spring-security-config:4.2.7.RELEASE
    Gradle: org.springframework.security:spring-security-core:4.2.7.RELEASE
    Gradle: org.springframework.security:spring-security-test:4.2.7.RELEASE
    Gradle: org.springframework.security:spring-security-web:4.2.7.RELEASE
    Gradle: org.springframework.ws:spring-ws-core:2.4.2.RELEASE
    Gradle: org.springframework.ws:spring-xml:2.4.2.RELEASE
    Gradle: org.springframework:spring-aop:4.3.18.RELEASE
    Gradle: org.springframework:spring-aspects:4.3.18.RELEASE
    Gradle: org.springframework:spring-beans:4.3.18.RELEASE
    Gradle: org.springframework:spring-context:4.3.18.RELEASE
    Gradle: org.springframework:spring-core:4.3.18.RELEASE
    Gradle: org.springframework:spring-expression:4.3.18.RELEASE
    Gradle: org.springframework:spring-jdbc:4.3.18.RELEASE
    Gradle: org.springframework:spring-jms:4.3.18.RELEASE
    Gradle: org.springframework:spring-messaging:4.3.18.RELEASE
    Gradle: org.springframework:spring-orm:4.3.18.RELEASE
    Gradle: org.springframework:spring-oxm:4.3.18.RELEASE
    Gradle: org.springframework:spring-test:4.3.18.RELEASE
    Gradle: org.springframework:spring-tx:4.3.18.RELEASE
    Gradle: org.springframework:spring-web:4.3.18.RELEASE
    Gradle: org.springframework:spring-webmvc:4.3.18.RELEASE
    Gradle: org.yaml:snakeyaml:1.17
    Gradle: stax:stax-api:1.0.1
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   João Menighin    6 年前

    使用所述解决方案解决了问题。 here .

    正如答案所说,WebLogic包括它自己的 joda.time 在类路径上使用它,除非我明确告诉它不要这样做。