ContextConfiguration RunWith WebAppConfiguration annotations together

自古美人都是妖i 提交于 2019-12-21 04:49:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!