[JUnit] Problem with Maven2 and cucumber-java

61 views
Skip to first unread message

Mikael Vik

unread,
May 20, 2009, 7:54:27 AM5/20/09
to Cukes
Cucumber is interfering with old JUnit-tests in a Maven-project. These
tests were running smoothly before we added Cucumber.

We have added cucumber-maven-plugin-0.0.2 and cucumber-java.0.0.2 to a
pretty standard Spring project with Spring MVC, Hibernate and Java
1.6, deploying to Tomcat and Jetty. The problem occurs only when
cucumber-java is added as a dependency.

The JUnit-tests do dependency injection in the setup of database
connections. The stacktrace identifies autowiring of sessionFactory as
the problem. During bean creation of sessionFactory we get a
NoSuchMethodError; probably because of trouble when initializing the
cglib class net.sf.cglib.proxy.Enhancer.

-- Test Class (autowiring daoImpl):
[code=java]
@ContextConfiguration(locations = {"/test-config-db.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class SdbCollectorDbTest {

@Autowired
private EventFactory eventFactory;

@Autowired
@Qualifier("sdbDaoImpl") // tried using autowiring by name, it
made no difference
protected SdbDao sdbDao;
[/code]

-- DaoImpl (autowiring sessionFactory):
[code=java]
@Repository
@Qualifier("sdbDaoImpl") // tried using autowiring by name, it made no
difference
@Transactional(readOnly = true)
public class SdbDaoImpl implements SdbDao {

@Autowired
private SessionFactory sessionFactory;
[/code]

-- Bean-config for sessionFactory and transactionManager:
[code=xml]
<context:component-scan base-package="...cut..."/>
<tx:annotation-driven/>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceNMHDB2P"/>
<property name="mappingResources">
<list>... cut...</list>
</property>
<property name="hibernateProperties">
...cut...
</property>

<property name="lobHandler" ref="defaultLobHandler"/>
</bean>
[/code]

-- Stacktrace:
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)
at
org.junit.internal.runners.JUnit4ClassRunner.runMethods
(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run
(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected
(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected
(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run
(JUnit4ClassRunner.java:42)
at com.intellij.rt.junit4.Junit4ClassSuite.run
(Junit4ClassSuite.java:99)
at com.intellij.rt.execution.junit.JUnitStarter.main
(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main
(AppMain.java:90)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sdbDaoImpl': Autowiring of fields
failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private org.hibernate.SessionFactory
<cut>.SdbDaoImpl.sessionFactory; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory' defined in class path
resource [datasource.xml]: Invocation of init method failed; nested
exception is java.lang.NoSuchMethodError:
org.objectweb.asm.ClassWriter.<init>(Z)V
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation
(AutowiredAnnotationBeanPostProcessor.java:243)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean
(AbstractAutowireCapableBeanFactory.java:959)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean
(AbstractAutowireCapableBeanFactory.java:472)
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:429)
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)
... 22 more
Caused by: org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private org.hibernate.SessionFactory
<cut>.adiseksport.dao.SdbDaoImpl.sessionFactory; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory' defined in class path
resource [datasource.xml]: Invocation of init method failed; nested
exception is java.lang.NoSuchMethodError:
org.objectweb.asm.ClassWriter.<init>(Z)V
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
$AutowiredFieldElement.inject
(AutowiredAnnotationBeanPostProcessor.java:435)
at
org.springframework.beans.factory.annotation.InjectionMetadata.injectFields
(InjectionMetadata.java:105)
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation
(AutowiredAnnotationBeanPostProcessor.java:240)
... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path
resource [datasource.xml]: Invocation of init method failed; nested
exception is java.lang.NoSuchMethodError:
org.objectweb.asm.ClassWriter.<init>(Z)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.findAutowireCandidates
(DefaultListableBeanFactory.java:671)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency
(DefaultListableBeanFactory.java:610)
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
$AutowiredFieldElement.inject
(AutowiredAnnotationBeanPostProcessor.java:412)
... 41 more
Caused by: java.lang.NoSuchMethodError:
org.objectweb.asm.ClassWriter.<init>(Z)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:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:
117)
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:302)
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:1300)
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)
... 53 more

aslak hellesoy

unread,
May 20, 2009, 8:13:59 AM5/20/09
to cu...@googlegroups.com
>
> Cucumber is interfering with old JUnit-tests in a Maven-project. These
> tests were running smoothly before we added Cucumber.
>
> We have added cucumber-maven-plugin-0.0.2 and cucumber-java.0.0.2 to a
> pretty standard Spring project with Spring MVC, Hibernate and Java
> 1.6, deploying to Tomcat and Jetty. The problem occurs only when
> cucumber-java is added as a dependency.
>

If you're not running cucumber, this is probably because the classpath
is altered in a way that it breaks something. Should we remove/change
the pom dependencies somewhere?

Aslak
Reply all
Reply to author
Forward
0 new messages