Announcement Announcement Module
No announcement yet.
@ContextConfiguration required Transactoins? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ContextConfiguration required Transactoins?


    During to migration from JUnit 3.8 to JUnit 4.4 I changed also definitions of my unit-test to use more annotations.

    I have quite small project - target of this project is to test web-services via CXF. So, this project has sprint-core, context and test in dependencies plus some libraries required for building CXF client.

    This project do not used any database, so, it has no any dataSource bean specified, as well as do not worked with transactions at all. So, it has no spring-tx in dependencies.

    Then I declared by unit-test as:
    public class BaseWsUnitTest {
    I've got an error during test exection:
    java.lang.NoClassDefFoundError: org/springframework/transaction/TransactionDefinition
    	at java.lang.Class.getDeclaredConstructors0(Native Method)
    	at java.lang.Class.privateGetDeclaredConstructors(
    	at java.lang.Class.getConstructor0(
    	at java.lang.Class.getDeclaredConstructor(
    	at org.springframework.beans.BeanUtils.instantiateClass(
    	at org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(
    	at org.springframework.test.context.TestContextManager.<init>(
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
    	at java.lang.reflect.Constructor.newInstance(
    	at org.junit.internal.requests.ClassRequest.buildRunner(
    	at org.junit.internal.requests.ClassRequest.getRunner(
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
    That means if it is required spring-tx. If I will add - it will start to tell me that it cannot find dataSource, "transactionManager" bean and so on and so on.

    So, is this requiremenets of Transactions by simple test runner a feature of Spring-Test - or it is a bug?

    Thank you for any suggestions

  • #2
    Hi akakunin,

    I just made a little test using only spring-core, spring-test, spring-test (all version 2.5.2), and Junit 4.4 and it works fine without transactions.

    Can you review your configurations or post extracts here so we can have a closer look?


    • #3
      Stefan, thank you for your answer!

      I found my problem in Spring Jira ( and seems it is already fixed in Spring 2.5.2.

      Unfortuantelly I cnanot switch to 2.52. until CXF 2.0.5 will not be released (due to some incompatibility problems). But I found solution for my case - declare Configuration Listeners for my test excluding transactinal one:
      @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})        						 
      public class BaseWsUnitTest {
      Now it works fine for me.


      • #4

        I didn't know the version of your Spring project so I made the assumption that your are using a current one.