Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

java - Error starting ApplicationContext: conflict with javax.persistence.Table

I am trying to run my project using spring-boot. It is possible to deploy the code as a jar and everything works fine. The tests do fail though.

I've been trying to use different version of my dependencies and did research on possible conflicts.

This is the extract of the POM.xml containing the dependencies:


<dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.0.1.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <!-- 
        mockServletResponse.setContentType() needs 
        org/springframework/http/MediaType 
        which is in:
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.0.1.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>5.4.15.Final</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.18</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.2</version>
        </dependency>
    </dependencies>

This is the error:

***************************
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:671)

The following method did not exist:

    'javax.persistence.SynchronizationType javax.persistence.PersistenceContext.synchronization()'

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

    jar:file:/Users/elias/Documents/Uni/HTW/3.%20Semester/KBE/%c3%9cbung/htwb-kbe-repo-template-master/lib/javax.persistence.jar!/javax/persistence/PersistenceContext.class
    jar:file:/Users/elias/.m2/repository/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar!/javax/persistence/PersistenceContext.class
    jar:file:/Users/elias/.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:/Users/elias/Documents/Uni/HTW/3.%20Semester/KBE/%c3%9cbung/htwb-kbe-repo-template-master/lib/javax.persistence.jar


Action:

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

2021-01-23 10:46:32.515 ERROR 6964 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@17d919b6] to prepare test instance [htw.kbe_beleg.controller.SongControllerTest@554188ac]

This is the output of mvn dependency:tree

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< htwb.ai.KBE_Beleg:songsWS >----------------------
[INFO] Building A Songs Web Service 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ songsWS ---
[INFO] htwb.ai.KBE_Beleg:songsWS:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.3.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.3.0.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.13.2:compile
[INFO] |  |  |  |  - org.apache.logging.log4j:log4j-api:jar:2.13.2:compile
[INFO] |  |  |  - org.slf4j:jul-to-slf4j:jar:1.7.30:compile
[INFO] |  |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] |  |  - org.yaml:snakeyaml:jar:1.26:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.11.0:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.11.0:compile
[INFO] |  |  - com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.11.0:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- org.glassfish:jakarta.el:jar:3.0.3:compile
[INFO] |  |  - org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.35:compile
[INFO] |  +- org.springframework:spring-web:jar:5.2.6.RELEASE:compile
[INFO] |  |  - org.springframework:spring-beans:jar:5.2.6.RELEASE:compile
[INFO] |  - org.springframework:spring-webmvc:jar:5.2.6.RELEASE:compile
[INFO] |     +- org.springframework:spring-aop:jar:5.2.6.RELEASE:compile
[INFO] |     +- org.springframework:spring-context:jar:5.2.6.RELEASE:compile
[INFO] |     - org.springframework:spring-expression:jar:5.2.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.3.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.3.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.3.0.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] |  |  - org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile
[INFO] |  |  - jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
[INFO] |  +- org.assertj:assertj-core:jar:3.16.1:test
[INFO] |  +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] |  +- org.mockito:mockito-junit-jupiter:jar:3.3.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.2.6.RELEASE:compile
[INFO] |  |  - org.springframework:spring-jcl:jar:5.2.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.2.6.RELEASE:test
[INFO] |  - org.xmlunit:xmlunit-core:jar:2.7.0:test
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.3.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:2.3.0.RELEASE:compile
[INFO] |  |  - org.aspectj:aspectjweaver:jar:1.9.5:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- com.zaxxer:HikariCP:jar:3.4.5:compile
[INFO] |  |  - org.springframework:spring-jdbc:jar:5.2.6.RELEASE:compile
[INFO] |  +- jakarta.transaction:jakarta.transaction-api:jar:1.3.3:compile
[INFO] |  +- jakarta.persistence:jakarta.persistence-api:jar:2.2.3:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.4.15.Final:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.24.0-GA:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.1.3.Final:compile
[INFO] |  |  +- com.fasterxml:classmate:jar:1.5.1:compile
[INFO] |  |  +- org.dom4j:dom4j:jar:2.1.3:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:5.1.0.Final:compile
[INFO] |  |  - org.glassfish.jaxb:jaxb-runtime:jar:2.3.3:compile
[INFO] |  |     +- org.glassfish.jaxb:txw2:jar:2.3.3:compile
[INFO] |  |     +- com.sun.istack:istack-commons-runtime:jar:3.0.11:compile
[INFO] |  |     - com.sun.activation:jakarta.activation:jar:1.2.2:runtime
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:2.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:5.2.6.RELEASE:compile
[INFO] |  |  - org.springframework:spring-tx:jar:5.2.6.RELEASE:compile
[INFO] |  - org.springframework:spring-aspects:jar:5.2.6.RELEASE:compile
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.6.2:test
[INFO] |  +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] |  +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |  - org.junit.platform:junit-platform-commons:jar:1.6.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.6.2:test
[INFO] |  - org.junit.platform:junit-platform-engine:jar:1.6.2:test
[INFO] +- javax.persistence:javax.persistence-api:jar:2.2:compile
[INFO] +- org.hibernate:hibernate-c3p0:jar:5.4.15.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
[INFO] |  - com.mchange:c3p0:jar:0.9.5.3:compile
[INFO] |     - com.mchange:mchange-commons-java:jar:0.2.15:compile
[INFO] +- org.postgresql:postgresql:jar:42.2.18:compile
[INFO] |  - org.checkerframework:checker-qual:jar:3.5.0:runtime
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.2:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:4.0.1:provided
[INFO] +- commons-io:commons-io:jar:2.6:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.10.2:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.2:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.11.3:compile
[INFO] |  +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.11.0:compile
[INFO] |  +- org.codehaus.woodstox:stax2-api:jar:4.2.1:compile
[INFO] |  - com.fasterxml.woodsto

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...