IDE 无法 运行 spring 引导无效常量类型 18
IDE fails to run spring boot invalid constant type 18
我目前正在将后端的一些代码部分重构为 java 8 个流。在这里,我使用了 lambda。
当我尝试 运行 我的 IDE 中的应用程序时,出现以下错误
当我 运行 使用 Maven 构建器的代码时它工作正常,只有当我 运行 IntelliJ 中的应用程序时它崩溃。我在其他地方读到它可能是我的 javassist。我尝试从我使用的其他依赖项中排除这些,但没有结果:(
另一个主题说我必须将 hamcrest 依赖项放在 pom 之上,也没有用..
我错过了什么?
Caused by: java.lang.RuntimeException: Error while reading file:/...path to project/target/classes/
at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:195) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:506) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:861) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
... 23 common frames omitted
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1113) ~[javassist-3.15.0-GA.jar:na]
at javassist.bytecode.ConstPool.read(ConstPool.java:1056) ~[javassist-3.15.0-GA.jar:na]
at javassist.bytecode.ConstPool.<init>(ConstPool.java:150) ~[javassist-3.15.0-GA.jar:na]
at javassist.bytecode.ClassFile.read(ClassFile.java:765) ~[javassist-3.15.0-GA.jar:na]
at javassist.bytecode.ClassFile.<init>(ClassFile.java:109) ~[javassist-3.15.0-GA.jar:na]
at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:246) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:212) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:173) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:126) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.doProcessElements(ExplodedJarVisitor.java:92) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:149) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:192) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
... 25 common frames omitted
我的pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<repositories>
...
</repositories>
<pluginrepositories>
...
</pluginrepositories>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>org.javassist</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>org.javassist</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1208</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.8.Final</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.6.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我的依赖关系树:
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.4:test
[INFO] | +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | | \- org.objenesis:objenesis:jar:2.1:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.4:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.4:test
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.4:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.4:test
[INFO] | +- junit:junit:jar:4.12:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.4:test
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:test
[INFO] +- org.projectlombok:lombok:jar:1.16.6:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.3.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.1.7:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.1.7:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile
[INFO] | | | \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] | +- org.thymeleaf:thymeleaf-spring4:jar:2.1.5.RELEASE:compile
[INFO] | | +- org.thymeleaf:thymeleaf:jar:2.1.5.RELEASE:compile
[INFO] | | | +- ognl:ognl:jar:3.0.8:compile
[INFO] | | | \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] | | \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] | \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
[INFO] | \- org.codehaus.groovy:groovy:jar:2.4.7:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.3.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.4:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.4:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.4:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | \- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.3.1:compile
[INFO] | +- org.springframework:spring-web:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework:spring-aop:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework:spring-beans:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | \- org.springframework:spring-context:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-expression:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] +- org.codehaus.sonar-plugins.java:sonar-jacoco-listeners:jar:1.2:test
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.8.9:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.apache.tomcat:tomcat-jdbc:jar:8.5.4:compile
[INFO] | | | \- org.apache.tomcat:tomcat-juli:jar:8.5.4:compile
[INFO] | | \- org.springframework:spring-jdbc:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:1.10.2.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:1.12.2.RELEASE:compile
[INFO] | | +- org.springframework:spring-orm:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework:spring-tx:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | \- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
[INFO] | \- org.springframework:spring-aspects:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] +- javax.transaction:jta:jar:1.1:compile
[INFO] +- org.postgresql:postgresql:jar:9.4.1208:compile
[INFO] +- org.hibernate:hibernate-core:jar:4.2.8.Final:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.2.8.Final:compile
[INFO] +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.6.5:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] +- com.fasterxml:jackson-xml-databind:jar:0.6.2:compile
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile
[INFO] | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
[INFO] | +- org.codehaus.jackson:jackson-xc:jar:1.9.2:compile
[INFO] | \- org.codehaus.woodstox:stax2-api:jar:3.1.0:compile
[INFO] | \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] +- com.mashape.unirest:unirest-java:jar:1.4.9:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] | \- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- org.apache.httpcomponents:httpasyncclient:jar:4.0.2:compile
[INFO] | \- org.apache.httpcomponents:httpcore-nio:jar:4.3.2:compile
[INFO] +- org.apache.httpcomponents:httpmime:jar:4.3.6:compile
[INFO] +- org.json:json:jar:20140107:compile
[INFO] +- org.webjars:bootstrap:jar:3.3.6:compile
[INFO] | \- org.webjars:jquery:jar:1.11.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.4.0.BUILD-SNAPSHOT:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:1.4.0.BUILD-SNAPSHOT:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.0.BUILD-SNAPSHOT:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] | | \- net.minidev:json-smart:jar:2.2.1:test
[INFO] | | \- net.minidev:accessors-smart:jar:1.1:test
[INFO] | | \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] | +- org.assertj:assertj-core:jar:2.4.1:test
[INFO] | +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.3.0:test
[INFO] | +- org.springframework:spring-core:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-test:jar:4.3.2.BUILD-SNAPSHOT:test
[INFO] +- commons-io:commons-io:jar:2.4:test
你的 pom 有点乱,因为你正在管理 Spring Boot 已经管理的东西。除此之外,您正在混合 2 个版本的框架,这是您永远不应该做的事情(无论框架如何)。
- 不要混合 1.3.5 和 1.4.0 版本的 Spring Boot
- Spring Boot manages hibernate 只需定义您要使用的版本即可。
- 我更喜欢测试依赖项排在最后(我建议使用
spring-boot-starter-test
依赖项,因为它也可以管理依赖项)。
- 删除 hibernate 和 javassist 依赖项(因为它们是为您管理的)
- 我建议使用 Mockito 而不是 Powermock(但这是个人偏好)。
- Spring Boot 还管理 postgres 版本,因此您可以删除版本标签(以及您拥有的 spring-boot 依赖项)。
你的 pom 应该看起来像这样。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<hibernate.version>4.2.8.Final</hibernate.version>
<powermock.version>1.6.4</powermock.version>
</properties>
然后在你的依赖项中做一些清理。
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</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</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- http://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- Dependencies for Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
我目前正在将后端的一些代码部分重构为 java 8 个流。在这里,我使用了 lambda。
当我尝试 运行 我的 IDE 中的应用程序时,出现以下错误
当我 运行 使用 Maven 构建器的代码时它工作正常,只有当我 运行 IntelliJ 中的应用程序时它崩溃。我在其他地方读到它可能是我的 javassist。我尝试从我使用的其他依赖项中排除这些,但没有结果:( 另一个主题说我必须将 hamcrest 依赖项放在 pom 之上,也没有用..
我错过了什么?
Caused by: java.lang.RuntimeException: Error while reading file:/...path to project/target/classes/
at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:195) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:506) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:861) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
... 23 common frames omitted
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1113) ~[javassist-3.15.0-GA.jar:na]
at javassist.bytecode.ConstPool.read(ConstPool.java:1056) ~[javassist-3.15.0-GA.jar:na]
at javassist.bytecode.ConstPool.<init>(ConstPool.java:150) ~[javassist-3.15.0-GA.jar:na]
at javassist.bytecode.ClassFile.read(ClassFile.java:765) ~[javassist-3.15.0-GA.jar:na]
at javassist.bytecode.ClassFile.<init>(ClassFile.java:109) ~[javassist-3.15.0-GA.jar:na]
at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:246) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:212) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:173) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:126) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(ExplodedJarVisitor.java:134) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.ExplodedJarVisitor.doProcessElements(ExplodedJarVisitor.java:92) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:149) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:192) ~[hibernate-entitymanager-4.2.8.Final.jar:4.2.8.Final]
... 25 common frames omitted
我的pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<repositories>
...
</repositories>
<pluginrepositories>
...
</pluginrepositories>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>org.javassist</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>org.javassist</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1208</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.8.Final</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.16.6.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我的依赖关系树:
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.4:test
[INFO] | +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | | \- org.objenesis:objenesis:jar:2.1:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.4:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.4:test
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.4:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.4:test
[INFO] | +- junit:junit:jar:4.12:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.4:test
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:test
[INFO] +- org.projectlombok:lombok:jar:1.16.6:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.3.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.1.7:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.1.7:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile
[INFO] | | | \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] | +- org.thymeleaf:thymeleaf-spring4:jar:2.1.5.RELEASE:compile
[INFO] | | +- org.thymeleaf:thymeleaf:jar:2.1.5.RELEASE:compile
[INFO] | | | +- ognl:ognl:jar:3.0.8:compile
[INFO] | | | \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] | | \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] | \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
[INFO] | \- org.codehaus.groovy:groovy:jar:2.4.7:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.3.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.4:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.4:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.4:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | \- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.3.1:compile
[INFO] | +- org.springframework:spring-web:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework:spring-aop:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework:spring-beans:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | \- org.springframework:spring-context:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-expression:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] +- org.codehaus.sonar-plugins.java:sonar-jacoco-listeners:jar:1.2:test
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.8.9:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.0.BUILD-SNAPSHOT:compile
[INFO] | | +- org.apache.tomcat:tomcat-jdbc:jar:8.5.4:compile
[INFO] | | | \- org.apache.tomcat:tomcat-juli:jar:8.5.4:compile
[INFO] | | \- org.springframework:spring-jdbc:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:1.10.2.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:1.12.2.RELEASE:compile
[INFO] | | +- org.springframework:spring-orm:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | +- org.springframework:spring-tx:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | | \- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
[INFO] | \- org.springframework:spring-aspects:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] +- javax.transaction:jta:jar:1.1:compile
[INFO] +- org.postgresql:postgresql:jar:9.4.1208:compile
[INFO] +- org.hibernate:hibernate-core:jar:4.2.8.Final:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.2.8.Final:compile
[INFO] +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.6.5:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] +- com.fasterxml:jackson-xml-databind:jar:0.6.2:compile
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile
[INFO] | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
[INFO] | +- org.codehaus.jackson:jackson-xc:jar:1.9.2:compile
[INFO] | \- org.codehaus.woodstox:stax2-api:jar:3.1.0:compile
[INFO] | \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] +- com.mashape.unirest:unirest-java:jar:1.4.9:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] | \- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- org.apache.httpcomponents:httpasyncclient:jar:4.0.2:compile
[INFO] | \- org.apache.httpcomponents:httpcore-nio:jar:4.3.2:compile
[INFO] +- org.apache.httpcomponents:httpmime:jar:4.3.6:compile
[INFO] +- org.json:json:jar:20140107:compile
[INFO] +- org.webjars:bootstrap:jar:3.3.6:compile
[INFO] | \- org.webjars:jquery:jar:1.11.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.4.0.BUILD-SNAPSHOT:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:1.4.0.BUILD-SNAPSHOT:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.0.BUILD-SNAPSHOT:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] | | \- net.minidev:json-smart:jar:2.2.1:test
[INFO] | | \- net.minidev:accessors-smart:jar:1.1:test
[INFO] | | \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] | +- org.assertj:assertj-core:jar:2.4.1:test
[INFO] | +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.3.0:test
[INFO] | +- org.springframework:spring-core:jar:4.3.2.BUILD-SNAPSHOT:compile
[INFO] | \- org.springframework:spring-test:jar:4.3.2.BUILD-SNAPSHOT:test
[INFO] +- commons-io:commons-io:jar:2.4:test
你的 pom 有点乱,因为你正在管理 Spring Boot 已经管理的东西。除此之外,您正在混合 2 个版本的框架,这是您永远不应该做的事情(无论框架如何)。
- 不要混合 1.3.5 和 1.4.0 版本的 Spring Boot
- Spring Boot manages hibernate 只需定义您要使用的版本即可。
- 我更喜欢测试依赖项排在最后(我建议使用
spring-boot-starter-test
依赖项,因为它也可以管理依赖项)。 - 删除 hibernate 和 javassist 依赖项(因为它们是为您管理的)
- 我建议使用 Mockito 而不是 Powermock(但这是个人偏好)。
- Spring Boot 还管理 postgres 版本,因此您可以删除版本标签(以及您拥有的 spring-boot 依赖项)。
你的 pom 应该看起来像这样。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<hibernate.version>4.2.8.Final</hibernate.version>
<powermock.version>1.6.4</powermock.version>
</properties>
然后在你的依赖项中做一些清理。
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</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</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- http://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- Dependencies for Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>