spring - tilesConfigurer: java.lang.IllegalArgumentException: Cannot resolve ServletContextResource without ServletContext -


updated

i seem have done uniquely wrong cannot find reference problem.

i trying integrate tiles extant spring thymeleaf/webflow/hibernate app.

everything works fine until add tilesconfigurer applicationcontext:

<!-- configures tiles layout system-->  	      <bean id="tilesconfigurer" class="org.thymeleaf.extras.tiles2.spring4.web.configurer.thymeleaftilesconfigurer">  	<property name="definitions">  		<list>  			<value>/web-inf/**/views.xml</value>  		</list>  	</property>  </bean>	

after adding configurer, test fail, but app still runs in tomcat8.

here typical test class:

package jake.prototype2.test.service;  import static org.junit.assert.assertfalse; import static org.junit.assert.asserttrue; import static org.junit.assert.fail;  import java.util.list;  import org.junit.test; import org.junit.runner.runwith;     import org.springframework.beans.factory.annotation.autowired; import org.springframework.test.context.contextconfiguration; import org.springframework.test.context.junit4.springjunit4classrunner;  import jake.prototype2.model.business.business; import jake.prototype2.service.user.businessservice; import jake.prototype2.test.testrunner.testss;  @runwith(springjunit4classrunner.class) @contextconfiguration("classpath:assessmentadmintl-servlet.xml") public class businessservicetest { @autowired private businessservice businessservice;  @test public void testgetbusinesses() {     testss.getlogger().info("testgetbusinesses");     list <business> blist=businessservice.getbusinesses();     asserttrue(blist.size()>0); }  @test public void testgetbusiness() {     testss.getlogger().info("testgetbusinesses");     business b=null;     try     {         b=businessservice.getbusiness(testss.getbusiness().getid());     }     catch(exception e)     {         testss.getlogger().error(e.getmessage(),e);         fail();     }      assertfalse(b==null); } } 

the resource specified in applicationcontext:

<context:component-scan base-package="jake.prototype2" />  	<mvc:resources mapping="/style/**" location="/style/" />  	<mvc:resources mapping="/images/**" location="/images/" />  	<mvc:resources mapping="/views/**" location="/web-inf/views/" />  	<mvc:annotation-driven />

web.xml specifes default servlet path:

      <servlet>        <servlet-name>assessmentadmintl</servlet-name>        <servlet-class>           org.springframework.web.servlet.dispatcherservlet        </servlet-class>        <load-on-startup>1</load-on-startup>     </servlet>        <servlet-mapping>      <servlet-name>assessmentadmintl</servlet-name>      <url-pattern>/</url-pattern>  </servlet-mapping>

i following exception on app initialization:

caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'tilesconfigurer' defined in url [file:/c:/users/jake/workspace/_ pt2/webcontent/web-inf/config/views_applicationcontext.xml]: invocation of init method failed; nested exception java.lang.illegalargumentexception: cannot resolve s ervletcontextresource without servletcontext @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1574) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:539) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:303) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:299) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:755) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:757) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:125) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abs

again, note, works fine until tilesconfigurer code inserted. appreciated.

with lot f @m.deinum answer calling context incorrectly.

my test class annotation should have been follows:

@webappconfiguration @contexthierarchy({ @contextconfiguration(locations = { "classpath:assessmentadmintl-servlet.xml" }) }) 

however, while solved problem specified here, still have other path related problems tilesconfigurer, (probably due lack of mock context?)

in short, serves specific answer specific problem. not whole story.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -