No such method error when creating JUnit test


IaCoder:

I've tried the problem for the past two days with no luck. I just want to create an annotation based JUnit test using spring framework and hibernate.

My IDE is netbeans 6.5 and I am using hibernate 3, spring 2.5.5 and JUnit 4.4.

This is the error I get:

Testcase: testFindContacts(com.mycontacts.data.dao.MyContactHibernateDaoTransactionTest):        Caused an ERROR
Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
        at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:203)
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:93)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:130)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [shared-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1337)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
        at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
        at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:42)
        at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173)
        at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:199)
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
        at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
        at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
        at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
        at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
        at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
        at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
        at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
        at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
        at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
        at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
        at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
        at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
        at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
        at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
        at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
        at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
        at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
        at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
        at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
        at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
Jared:

will java.lang.NoSuchMethodErroralways indicate that the version of the class that is on your compiler's classpath is different from the version of the class on the classpath at runtime (there are methods missing at compile time and the compilation fails.)

In this case, the version org.objectweb.asm.ClassWriteron the classpath at compile time is different from the version on the classpath at runtime .

Related


JUnit test for @override method

Brandon Bischoff: I have a program with a class below it: public class Plane implements Flyable { private final int numberOfEngines; private final String model; public Plane(int engines, String m) { numberOfEngines = engines;

Test the main method with junit

user2719152: I have written a class which takes data from console and input parameters in main method. The main method calls different methods for different console inputs, and calls different functions for different parameters. So I want to test this main met

JUNIT test void method

between I have a Java class full of void methods and I want to do some unit tests for maximum code coverage. For example I have this method: protected static void checkifValidElements(int arg1, int arg2) { method1(arg1); method2(arg1); method3(arg

Junit test method

Eugene: What are the most common testing methods I should use first in order to become familiar with unit testing? There are a lot of them, but I guess something like normal. I mean Junit methods like AssertTrue() etc. Andy Thomas: There are only a few pattern

Junit test boolean method

Splitter I have a problem writing a test case in the following method:EvenNum(double) public class OddEven { /** * @param args */ public boolean evenNum(double num) { if(num%2 == 0) { System.out.print(true); return true; } e

Error creating bean in Spring Boot's JUnit test

Zychoo I am creating application in Spring Boot.The service I created looks like this: @Service public class MyService { @Value("${myprops.hostname}") private String host; public void callEndpoint() { String endpointUrl = this.host + "/en

JUnit test transaction method

Tudani Hetimura I am new to JUnit and trying to test a spring web service using JPA DAO. I need to test a service method similar to the following. Service methods are annotated @Transactional(propagation=Propagation.REQUIRED)and ServiceObjectRepository.update(

Test the main method with junit

user2719152: I have written a class which takes data from console and input parameters in main method. The main method calls different methods for different console inputs, and calls different functions for different parameters. So I want to test this main met

JUNIT test void method

between I have a Java class full of void methods and I want to do some unit tests for maximum code coverage. For example I have this method: protected static void checkifValidElements(int arg1, int arg2) { method1(arg1); method2(arg1); method3(arg

Detect failure or error of Junit test in @After method

Ralph: Is there a way in JUnit to detect a test case for a test failure or error in an annotated @After method? An ugly solution is this: boolean withoutFailure = false; @Test void test() { ... asserts... withoutFailure = true; } @After public void tea

Junit test boolean method

Splitter I have a problem writing a test case in the following method:EvenNum(double) public class OddEven { /** * @param args */ public boolean evenNum(double num) { if(num%2 == 0) { System.out.print(true); return true; } e

Junit test method

Eugene: What are the most common testing methods I should use first in order to become familiar with unit testing? There are a lot of them, but I guess something like normal. I mean Junit methods like AssertTrue() etc. Andy Thomas: There are only a few pattern

No such method error when running JUnit tests

Jesse James When I try to run the JUnit class, I get the following error: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1083

JUnit test for setter method

james public class Room extends java.lang.Object implements java.io.Serializable { public String description; public Map<String, Room> map; public List<Thing> things; //Room //Parameters:

Junit test Rxjava method

Milad Salimi The method I tested Rxjavamany times without issue , but now I am facing this problem : Null pointer exceptionat this subscribeOn(Schedulers.io())line. fun registerPhone(phoneNumber: String, nationalId: String) { val disposable =

Error creating bean in Spring Boot's JUnit test

Zychoo I am creating application in Spring Boot. The service I created looks like this: @Service public class MyService { @Value("${myprops.hostname}") private String host; public void callEndpoint() { String endpointUrl = this.host + "/e

Unable to test method with JUnit

Ken I am unable to test the hasNext() method in the IterableIntegerArrays class. If I call this method in IterableIntegerArraysTestCases it says "Cannot find symbol". How should I fix this error? public class IterableIntegerArrays extends IntegerRelation imple

Junit test Rxjava method

Milad Salimi The method I tested Rxjavamany times without issue , but now I am facing this problem : Null pointer exceptionat this subscribeOn(Schedulers.io())line. fun registerPhone(phoneNumber: String, nationalId: String) { val disposable =

JUnit test method not executing

Devendra Singh I have a DateAdapter class in which I marshall a Date type to String type and String data type to Date by 2 methods mrashhall and unmarshall. So my test method is not running. public class DateAdapter extends XmlAdapter<String, LocalDate> { pri

Detect failure or error of Junit test in @After method

Ralph: Is there a way in JUnit to detect a test case for a test failure or error in an annotated @After method? An ugly solution is this: boolean withoutFailure = false; @Test void test() { ... asserts... withoutFailure = true; } @After public void tea

Detect failure or error of Junit test in @After method

Ralph: Is there a way in JUnit to detect a test case for a test failure or error in an annotated @After method? An ugly solution is this: boolean withoutFailure = false; @Test void test() { ... asserts... withoutFailure = true; } @After public void tea

No such method error when creating JUnit test

IaCoder: I've tried the problem for the past two days with no luck. I just want to create an annotation based JUnit test using spring framework and hibernate. My IDE is netbeans 6.5 and I am using hibernate 3, spring 2.5.5 and JUnit 4.4. This is the error I ge

Error creating bean in Spring Boot's JUnit test

Zychoo I am creating application in Spring Boot. The service I created looks like this: @Service public class MyService { @Value("${myprops.hostname}") private String host; public void callEndpoint() { String endpointUrl = this.host + "/e

Detect failure or error of Junit test in @After method

Ralph: Is there a way in JUnit to detect a test case for a test failure or error in an annotated @After method? An ugly solution is this: boolean withoutFailure = false; @Test void test() { ... asserts... withoutFailure = true; } @After public void tea