I am attempting to build an initial junit test for our struts 2 spring 3, hibernate web application. I attempt the run the following test and keep gettting the same error. Im all google'd out and have yet to find an answer. thanks!
relevant context entries:Code:public class TestJunitJobOrderAction extends AbstractStruts2SpringJunit4 { @Test public void testOrdersAction() throws Exception { ActionProxy proxy = super.getActionProxy("/acct/orders"); ActionContext actionContext = proxy.getInvocation().getInvocationContext(); String str = (String) applicationContext.getBean("payPeriodString"); //.....removed for brevity } } @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( { "classpath:testContext.xml" }) public abstract class AbstractStruts2SpringJunit4 extends StrutsTestCase implements ApplicationContextAware { protected static ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } @Before public void setUp() throws Exception { super.setUp(); } @Override protected void setupBeforeInitDispatcher() throws Exception { servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); } }
error returned:HTML Code:<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer"> <property name="scopes"> <map> <entry key="session"> <bean class="org.springframework.context.support.SimpleThreadScope"/> </entry> <entry key="request"> <bean class="org.springframework.web.context.request.RequestScope" /> </entry> </map> </property> </bean> <bean id="payPeriodString" class="java.lang.String" factory-bean="payPeriodFacade" factory-method="getPayPeriodString" lazy-init="true" scope="session"> </bean> <bean id="payPeriodFacade" class="ataaps.biz.facade.PayPeriodFacade" scope="request"> <aop:scoped-proxy/><!-- this is not here in production config --> </bean>
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'payPeriodString' defined in class path resource [testContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Factory method [public java.lang.String ataaps.biz.facade.PayPeriodFacade.getPayPeriodStri ng()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.payPeriodFacade': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.


Reply With Quote
