Skip to content

Make Spring ContextTest annotation support WebApplicationContext [SPR-4759] #9436

Closed
@spring-projects-issues

Description

@spring-projects-issues

Yaozong Zhu opened SPR-4759 and commented

I am trying to integrate my tests into Spring 2.5 availing of TestContext annotations. But I met a support issue. The followings are relevant codes:

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners(value = {
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class
})
@ContextConfiguration(locations = {
"classpath:/applicationContext-resources.xml",
"classpath*:/applicationContext.xml"
}, inheritLocations = true)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public abstract class BaseTestCase extends AbstractJUnit4SpringContextTests {...}

@ContextConfiguration(locations = {
"classpath:/applicationContext-jmx.xml",
"/WEB-INF/applicationContext*.xml",
"/WEB-INF/dispatcher-servlet.xml"
}, inheritLocations = true)
public abstract class BaseWebControllerTestCase extends BaseTestCase{...}

public class UserFormControllerTest extends BaseWebControllerTestCase{
@Autowired
private UserFormController c = null;

@Test
...
}

java.lang.IllegalStateException: WebApplicationObjectSupport instance [xxx.UserFormController@123961b] does not run in a WebApplicationContext but in: org.springframework.context.support.GenericApplicationContext@1fc2fb: display name [org.springframework.context.support.GenericApplicationContext@1fc2fb]; startup date [Mon Apr 28 15:35:37 BST 2008]; root of context hierarchy
at org.springframework.web.context.support.WebApplicationObjectSupport.getWebApplicationContext(WebApplicationObjectSupport.java:101)
at org.springframework.web.context.support.WebApplicationObjectSupport.getServletContext(WebApplicationObjectSupport.java:115)
...


Affects: 2.5.2

Issue Links:

1 votes, 1 watchers

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions