java - Why unit testing with Spring 3.1 WebMvcConfig fails? -


from spring 3.1, can use javaconfig more @enable* annotations.

so made webconfig set webmvc configuration, , tried test it. if extends webmvcconfigureradapter or webmvcconfigurationsupport webconfig unit test fails because of lack of servletcontext. code , messages below.

webconfig.java

@configuration @enablewebmvc public class webconfig extends webmvcconfigurationsupport {} 

test.java

@runwith(springjunit4classrunner.class) @contextconfiguration(classes=webconfig.class) public class testfail {     @test     public void test() {} } 

message

java.lang.illegalstateexception: failed load applicationcontext     @ org.springframework.test.context.testcontext.getapplicationcontext(testcontext.java:157)     @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.injectdependencies(dependencyinjectiontestexecutionlistener.java:109)     @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.preparetestinstance(dependencyinjectiontestexecutionlistener.java:75) ... caused by: java.lang.illegalargumentexception: servletcontext required configure default servlet handling     @ org.springframework.util.assert.notnull(assert.java:112)     @ org.springframework.web.servlet.config.annotation.defaultservlethandlerconfigurer.<init>(defaultservlethandlerconfigurer.java:54)     @ org.springframework.web.servlet.config.annotation.webmvcconfigurationsupport.defaultservlethandlermapping(webmvcconfigurationsupport.java:253)     @ com.zum.news.comments.web.webconfig$$enhancerbycglib$$8bbfcca1.cglib$defaultservlethandlermapping$10(<generated>)     @ com.zum.news.comments.web.webconfig$$enhancerbycglib$$8bbfcca1$$fastclassbycglib$$19b86ad0.invoke(<generated>)     @ net.sf.cglib.proxy.methodproxy.invokesuper(methodproxy.java:215)     @ org.springframework.context.annotation.configurationclassenhancer$beanmethodinterceptor.intercept(configurationclassenhancer.java:280)     @ com.zum.news.comments.web.webconfig$$enhancerbycglib$$8bbfcca1.defaultservlethandlermapping(<generated>)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:149)     ... 41 more 

how unit test webconfig properly?

edit

as garcia said, bug fixed in spring 3.2.0.rc1.

just add @webappconfiguration annotation in test class.

@runwith(springjunit4classrunner.class) @webappconfiguration @contextconfiguration(classes=webconfig.class) public class testfail {     @test     public void test() {} } 

there bug in spring 3.1, can find answer in these 2 issues:

please let know if find workaround spring 3.1, if not must wait until 3.2 out there. have i've tried spring 3.2.0.m2 , still not working me.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -