0
votes

I have configured Junit 4 with Spring 3.2.8 where I have used JDK 8. Here is my test controller class

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { WebConfig.class })
public class TManagerTest {

    @Autowired
    private TestManager  testManager ;

    @Test
    public void test() {
        this.testManager.getAll();
    }

}`

When I try to run application I'm getting this error:

ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file ././TManagerTest .java

When I search issue I found Spring 3.x support upto JDK 7. So it has to compile with JDK 7 but we can use JRE 8.

Is it true ? If yes my question is when I create classes with annotated @Service, @Controller and run application it works fine. Why does the error occur with junit only? If it is the case then it should not work with other than junit too.

If i want to use spring 3.2.8 , with jdk 8 .

1
your error comes from ASM. I wonder if you exclude and use a newer version of asm in your spring dependencies, would this work? - Eugene
"Why i am getting error with junit only." - Find the source of the problem first and then this question probably answers itself. A likely reason is that tests have their own classpath to be able to add test-specific libraries (such as junit), maybe something is going wrong there. - Gimby
@Gimby when i compile same code with jdk 7 with jre 8 it work fine - salman irfan khandu
don't use Spring 3.x.x . It has reached EOL. Look here - JimHawkins
@salman Yeah so the "it works" scenario is that you're running java 7 bytecode on Java 8. That is not unexpected when you take the error message into account. - Gimby

1 Answers

1
votes

You need Spring 4 if you want compile code to Java 8 (target 1.8), but you can still run apps on Java 8 compiled to Java 7 if you run on Spring 3.2.x .

As per spring reference documentation:

Note that the Java 8 bytecode level (-target 1.8, as required by -source 1.8) is only fully supported as of Spring Framework 4.0. In particular, Spring 3.2 based applications need to be compiled with a maximum of Java 7 as the target, even if they happen to be deployed onto a Java 8 runtime. Please upgrade to Spring 4 for Java 8 based applications.