1

Im trying to run a simple JPA spring web page, but i'm having trouble with getting it to recognize javax.persistence, or maybe I have conflicts of imports.

So far I have tried removing many maven dependencies to try finding a conflict as a few other stackoverflow answers involved this and I was unable to. I also tried adding the persistence api dependency but it did not help

These are my dependencies in pom.xml

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>


    </dependencies>

and this is the error I am getting when running the program

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.<init>(PersistenceAnnotationBeanPostProcessor.java:665)

The following method did not exist:

    javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;

The method's class, javax.persistence.PersistenceContext, is available from the following locations:

    jar:file:/C:/Users/hicks/IdeaProjects/CodeSite/lib/javax.persistence.jar!/javax/persistence/PersistenceContext.class
    jar:file:/C:/Users/hicks/.m2/repository/javax/persistence/javax.persistence-api/2.2/javax.persistence-api-2.2.jar!/javax/persistence/PersistenceContext.class

It was loaded from the following location:

    file:/C:/Users/hicks/IdeaProjects/CodeSite/lib/javax.persistence.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.persistence.PersistenceContext

Running maven dependency:tree -Dverbose returns this tree, which shows only one occurrence of javax.persistence-api:

[INFO] ------------------------------------------------------------------------
[INFO] Building codesite 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ demo ---
[INFO] Verbose not supported since maven-dependency-plugin 3.0
[INFO] jacob:demo:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:2.1.4.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.9.2:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- com.zaxxer:HikariCP:jar:3.2.0:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:5.1.6.RELEASE:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.3:compile
[INFO] |  +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] |  |  \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.3.9.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  +- javax.persistence:javax.persistence-api:jar:2.2:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.23.1-GA:compile
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.9.12:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.0.5.Final:compile
[INFO] |  |  +- com.fasterxml:classmate:jar:1.4.0:compile
[INFO] |  |  +- org.dom4j:dom4j:jar:2.1.1:compile
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.4.Final:compile
[INFO] |  \- org.springframework:spring-aspects:jar:5.1.6.RELEASE:compile
[INFO] +- mysql:mysql-connector-java:jar:8.0.15:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.1.4.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.11.2:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.26:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.23:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.8:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.8:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.17:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.17:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.17:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.16.Final:compile
[INFO] |  |  \- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.1.6.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.1.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.4.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.4.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.4.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.11.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.23.4:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.9.12:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:5.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.1.6.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.6.2:test
[INFO] +- commons-io:commons-io:jar:2.1:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.8:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.9.8:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.8:compile
[INFO] +- io.projectreactor:reactor-test:jar:3.2.8.RELEASE:test
[INFO] |  \- io.projectreactor:reactor-core:jar:3.2.8.RELEASE:compile
[INFO] |     \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
[INFO] +- org.springframework.data:spring-data-commons:jar:2.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.26:compile
[INFO] +- org.springframework.data:spring-data-jpa:jar:2.1.6.RELEASE:runtime
[INFO] |  +- org.springframework:spring-orm:jar:5.1.6.RELEASE:runtime
[INFO] |  +- org.springframework:spring-context:jar:5.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjrt:jar:1.9.2:runtime
[INFO] +- org.springframework.session:spring-session-core:jar:2.1.5.RELEASE:compile
[INFO] |  \- org.springframework:spring-jcl:jar:5.1.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.1.4.RELEASE:runtime
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.1.4.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:2.1.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-webflux:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.1.4.RELEASE:compile
[INFO] |  |  \- io.projectreactor.netty:reactor-netty:jar:0.8.6.RELEASE:compile
[INFO] |  |     +- io.netty:netty-codec-http:jar:4.1.34.Final:compile
[INFO] |  |     |  +- io.netty:netty-common:jar:4.1.34.Final:compile
[INFO] |  |     |  +- io.netty:netty-buffer:jar:4.1.34.Final:compile
[INFO] |  |     |  +- io.netty:netty-transport:jar:4.1.34.Final:compile
[INFO] |  |     |  |  \- io.netty:netty-resolver:jar:4.1.34.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec:jar:4.1.34.Final:compile
[INFO] |  |     +- io.netty:netty-codec-http2:jar:4.1.34.Final:compile
[INFO] |  |     +- io.netty:netty-handler:jar:4.1.34.Final:compile
[INFO] |  |     +- io.netty:netty-handler-proxy:jar:4.1.34.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec-socks:jar:4.1.34.Final:compile
[INFO] |  |     \- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.34.Final:compile
[INFO] |  |        \- io.netty:netty-transport-native-unix-common:jar:4.1.34.Final:compile
[INFO] |  +- org.springframework:spring-webflux:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.synchronoss.cloud:nio-multipart-parser:jar:1.1.0:compile
[INFO] |     \- org.synchronoss.cloud:nio-stream-storage:jar:1.1.3:compile
[INFO] +- de.codecentric:spring-boot-admin-starter-server:jar:2.1.4:compile
[INFO] |  +- de.codecentric:spring-boot-admin-server:jar:2.1.4:compile
[INFO] |  |  \- io.projectreactor.addons:reactor-extra:jar:3.2.2.RELEASE:compile
[INFO] |  +- de.codecentric:spring-boot-admin-server-ui:jar:2.1.4:compile
[INFO] |  \- de.codecentric:spring-boot-admin-server-cloud:jar:2.1.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.1.4.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:2.1.4.RELEASE:compile
[INFO] |  \- io.micrometer:micrometer-core:jar:1.1.4:compile
[INFO] |     +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
[INFO] |     \- org.latencyutils:LatencyUtils:jar:2.0.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-cache:jar:2.1.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-context-support:jar:5.1.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:2.1.4.RELEASE:compile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.6.2:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring5:jar:3.0.11.RELEASE:compile
[INFO] |  |  \- org.thymeleaf:thymeleaf:jar:3.0.11.RELEASE:compile
[INFO] |  |     +- org.attoparser:attoparser:jar:2.0.5.RELEASE:compile
[INFO] |  |     \- org.unbescape:unbescape:jar:1.1.6.RELEASE:compile
[INFO] |  \- org.thymeleaf.extras:thymeleaf-extras-java8time:jar:3.0.4.RELEASE:compile
[INFO] \- org.springframework.boot:spring-boot-starter-web-services:jar:2.1.4.RELEASE:compile
[INFO]    +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.5.0:compile
[INFO]    |  +- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
[INFO]    |  +- org.jvnet.mimepull:mimepull:jar:1.9.11:compile
[INFO]    |  \- org.jvnet.staxex:stax-ex:jar:1.8:compile
[INFO]    +- javax.xml.ws:jaxws-api:jar:2.3.1:compile
[INFO]    +- org.springframework:spring-oxm:jar:5.1.6.RELEASE:compile
[INFO]    \- org.springframework.ws:spring-ws-core:jar:3.0.7.RELEASE:compile
[INFO]       \- org.springframework.ws:spring-xml:jar:3.0.7.RELEASE:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
4

1 回答 1

1

我看到你的 spring 数据依赖版本有冲突一个是 2.1.6 另一个是 2.1.4 请删除 2.1.4 版本并将 2.1.6 范围更改为默认值(编译)

于 2019-05-01T12:29:58.167 回答