Spring JUnit在终端中工作,但不在intellij中工作

Spring JUnit在终端中工作,但不在intellij中工作,spring,junit,intellij-idea,Spring,Junit,Intellij Idea,我在intellij中运行junit测试时遇到问题。我得到的错误如下: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/grails/dist/grails-plugin-log4j-2.3.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/g

我在intellij中运行junit测试时遇到问题。我得到的错误如下:

 SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/grails/dist/grails-plugin-log4j-2.3.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/grails/lib/org.slf4j/slf4j-simple/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/dev/maven/repository/org/slf4j/slf4j-log4j12/1.7.7/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.GrailsSlf4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\dev\projects\SlaveDriver\target\classes\com\r\slavedriver\service\ServerDetailsImpl.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [C:\dev\projects\SlaveDriver\target\classes\com\r\slavedriver\service\ServerDetailsImpl.class]; nested exception is java.lang.IllegalArgumentException
    ... 12 more
Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [C:\dev\projects\SlaveDriver\target\classes\com\r\slavedriver\service\ServerDetailsImpl.class]; nested exception is java.lang.IllegalArgumentException
    ... 12 more
Caused by: java.lang.IllegalArgumentException
我发现了一些关于这个问题的帖子,似乎与jdk或旧的spring版本有关,但我所有的东西都是最新的,jdk1.8和Spring4 对可能出现的问题有什么建议吗

谢谢

附言:


1.8
UTF-8
UTF-8
1.7.7
4.0.5.1发布
2.4.0
1.5.0.1发布
1.0.1.最终版本
4.2.9.最终版本
5.1.30
3
4.11
org.slf4j
slf4j api
${org.slf4j.version}
org.slf4j
slf4j-log4j12
${org.slf4j.version}
运行时
org.slf4j
jcl-over-slf4j
${org.slf4j.version}
运行时
org.springframework
spring上下文
${org.springframework.version}
公用记录
公用记录
org.springframework
弹簧网
${org.springframework.version}
org.springframework
SpringWebMVC
${org.springframework.version}
org.springframework
弹簧oxm
${org.springframework.version}
com.fasterxml.jackson.core
杰克逊数据绑定
${com.fasterxml.jackson.version}
com.fasterxml.jackson.core
杰克逊核心
${com.fasterxml.jackson.version}
javax.servlet
javax.servlet-api
3.0.1
假如
org.springframework.data
spring数据jpa
${org.springframework.data jpa.version}
org.springframework
春季甲虫
${org.springframework.version}
org.hibernate
休眠实体管理器
${hibernate.version}
org.hibernate
冬眠核心
${hibernate.version}
org.springframework
德克萨斯州春季
${org.springframework.version}
mysql
mysql连接器java
${mysql.connector.version}
朱尼特
朱尼特
${junit.version}
测试
org.springframework
弹簧试验
${org.springframework.version}
测试
公共dbcp
公共dbcp
1.2.2
org.apache.maven.plugins
maven编译器插件
3
${jdk.version}
${jdk.version}
org.flywaydb
FlywayMaven插件
${flywaydb.version}
jdbc:mysql://localhost/slave_driver
根
h0liday
com.mysql.jdbc.Driver
数据库/应用程序/迁移
mysql
mysql连接器java
${mysql.connector.version}
org.apache.maven.plugins
maven战争插件
2.4
假的
org.apache.tomcat.maven
tomcat7 maven插件
2.2
8080
src/test/resources/tomcat-context.xml
这就是问题所在:

ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [C:\dev\projects\SlaveDriver\target\classes\com\rentalcars\slavedriver\service\ServerDetailsImpl.class]; nested exception is java.lang.IllegalArgumentException
显然,只有Spring4支持Java8

另外,查看maven依赖关系图,并排除重复的sl4j绑定

 <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>${hibernate.version}</version>
            <scope>${defaultScope}</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

org.hibernate
休眠ehcache
${hibernate.version}
${defaultScope}
org.slf4j
slf4j-log4j12

显然,他使用的是log4j(从log4j消息判断),我将退出
slf4j simple
。我已经添加了pom.xml文件,不确定什么是重复的,需要删除。richgt单击pom>diagrams>可以查看重复的依赖项。但是您首先需要更改spring版本或jdk版本我需要将jdk和spring更改为什么版本?我已经使用了jdk 1.8和spring 4.0.5,如果我在图中的pom.xml>上设置了正确的时钟,我看到的唯一选项是显示更改。错误表示这与ASM classreader无法解析类文件有关。请确保IntelliJ和maven中的编译器设置相同。
 <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>${hibernate.version}</version>
            <scope>${defaultScope}</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>