问题
I have class which annotated these annotations:
@ContextConfiguration(locations = { "classpath:pathToXml.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
Can you explain what features I had after I added these annotation on my class ?
回答1:
You'll get the features described in @WebAppConfiguration configuration javadoc.
WebApplicationContext mostly changes the way resources are loaded, i.e. resources with unspecifed resource prefix will be loaded from src/main/webapp or from the location in value parameter(they won't be available in Spring context otherwise, because usually webapp folder is not included to classpath) instead of classpath:.
Also you will be able to to test the code which uses other WebApplicationContext features- ServletContextAware beans, Session and Request bean scopes etc.
That means that you will be able to use Spring MVC Test Framework
来源:https://stackoverflow.com/questions/19154152/contextconfiguration-runwith-webappconfiguration-annotations-together