<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: No Scope registered for scope request</title>
	<atom:link href="http://www.javathinking.com/2009/06/no-scope-registered-for-scope-request/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javathinking.com/2009/06/no-scope-registered-for-scope-request/</link>
	<description>Java and software development related thoughts</description>
	<lastBuildDate>Thu, 29 Dec 2011 20:59:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Kalyan Dasika</title>
		<link>http://www.javathinking.com/2009/06/no-scope-registered-for-scope-request/comment-page-1/#comment-1721</link>
		<dc:creator>Kalyan Dasika</dc:creator>
		<pubDate>Thu, 29 Dec 2011 20:59:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.javathinking.com/?p=300#comment-1721</guid>
		<description>With the above solution I was still getting &quot;Caused by: java.lang.IllegalStateException: No Scope registered for scope &#039;request&#039;&quot;

So, I ended up creating a mock BeanFactoryPostProcessor (in the test/java area) that does the same thing.. 

@Component
public class MockRequestBeanFactoryPostProcessor implements BeanFactoryPostProcessor{

	public void postProcessBeanFactory(
			ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println(&quot;Setting up a mock request for unit testing..&quot;);
		beanFactory.registerScope(&quot;request&quot;, new RequestScope());
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);		
	}
	
}</description>
		<content:encoded><![CDATA[<p>With the above solution I was still getting &#8220;Caused by: java.lang.IllegalStateException: No Scope registered for scope &#8216;request&#8217;&#8221;</p>
<p>So, I ended up creating a mock BeanFactoryPostProcessor (in the test/java area) that does the same thing.. </p>
<p>@Component<br />
public class MockRequestBeanFactoryPostProcessor implements BeanFactoryPostProcessor{</p>
<p>	public void postProcessBeanFactory(<br />
			ConfigurableListableBeanFactory beanFactory) throws BeansException {<br />
		System.out.println(&#8220;Setting up a mock request for unit testing..&#8221;);<br />
		beanFactory.registerScope(&#8220;request&#8221;, new RequestScope());<br />
		MockHttpServletRequest request = new MockHttpServletRequest();<br />
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);<br />
		RequestContextHolder.setRequestAttributes(attributes);<br />
	}</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trung Hoang</title>
		<link>http://www.javathinking.com/2009/06/no-scope-registered-for-scope-request/comment-page-1/#comment-1554</link>
		<dc:creator>Trung Hoang</dc:creator>
		<pubDate>Mon, 19 Jul 2010 08:00:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.javathinking.com/?p=300#comment-1554</guid>
		<description>For those using junit 4 and spring 3, i adapted Paul&#039;s code:

    @Before
    public void setup() {
        ConfigurableBeanFactory configurableBeanFactory = (ConfigurableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
        configurableBeanFactory.registerScope(&quot;session&quot;, new SessionScope());
        configurableBeanFactory.registerScope(&quot;request&quot;, new RequestScope());
        MockHttpServletRequest request = new MockHttpServletRequest();
        ServletRequestAttributes attributes = new ServletRequestAttributes(request);
        RequestContextHolder.setRequestAttributes(attributes);
    }

Be sure not to autowire your controller. Just use applicationContext.getBean() in the setup or in your test method.</description>
		<content:encoded><![CDATA[<p>For those using junit 4 and spring 3, i adapted Paul&#8217;s code:</p>
<p>    @Before<br />
    public void setup() {<br />
        ConfigurableBeanFactory configurableBeanFactory = (ConfigurableBeanFactory) applicationContext.getAutowireCapableBeanFactory();<br />
        configurableBeanFactory.registerScope(&#8220;session&#8221;, new SessionScope());<br />
        configurableBeanFactory.registerScope(&#8220;request&#8221;, new RequestScope());<br />
        MockHttpServletRequest request = new MockHttpServletRequest();<br />
        ServletRequestAttributes attributes = new ServletRequestAttributes(request);<br />
        RequestContextHolder.setRequestAttributes(attributes);<br />
    }</p>
<p>Be sure not to autowire your controller. Just use applicationContext.getBean() in the setup or in your test method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Mark Bram</title>
		<link>http://www.javathinking.com/2009/06/no-scope-registered-for-scope-request/comment-page-1/#comment-1486</link>
		<dc:creator>Robert Mark Bram</dc:creator>
		<pubDate>Tue, 06 Apr 2010 04:13:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.javathinking.com/?p=300#comment-1486</guid>
		<description>I was getting this error too. I don&#039;t understand the error or how your solution works. How are you initialising &quot;context&quot; and &quot;attributes&quot;?

I tried initialising them like so:
ConfigurableApplicationContext context = getContext(null);
ServletRequestAttributes attributes = new ServletRequestAttributes(request);

However, it didn&#039;t solve my problem, so I kept looking and found this post in mail-archives.apache.org: http://bit.ly/bO5HdU

It says I needed to define my bean in both ApplicationContext and faces-config.

Still don&#039;t understand it, but I have green bar and need to move on.. 

Rob
:)</description>
		<content:encoded><![CDATA[<p>I was getting this error too. I don&#8217;t understand the error or how your solution works. How are you initialising &#8220;context&#8221; and &#8220;attributes&#8221;?</p>
<p>I tried initialising them like so:<br />
ConfigurableApplicationContext context = getContext(null);<br />
ServletRequestAttributes attributes = new ServletRequestAttributes(request);</p>
<p>However, it didn&#8217;t solve my problem, so I kept looking and found this post in mail-archives.apache.org: <a href="http://bit.ly/bO5HdU" rel="nofollow">http://bit.ly/bO5HdU</a></p>
<p>It says I needed to define my bean in both ApplicationContext and faces-config.</p>
<p>Still don&#8217;t understand it, but I have green bar and need to move on.. </p>
<p>Rob<br />
 <img src='http://www.javathinking.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: paul</title>
		<link>http://www.javathinking.com/2009/06/no-scope-registered-for-scope-request/comment-page-1/#comment-1447</link>
		<dc:creator>paul</dc:creator>
		<pubDate>Tue, 10 Nov 2009 09:58:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.javathinking.com/?p=300#comment-1447</guid>
		<description>It&#039;s been available on AbtractApplicationContext from at least spring 2.0 :

http://static.springsource.org/spring/docs/3.0.0.RC1/javadoc-api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29
http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29
http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29</description>
		<content:encoded><![CDATA[<p>It&#8217;s been available on AbtractApplicationContext from at least spring 2.0 :</p>
<p><a href="http://static.springsource.org/spring/docs/3.0.0.RC1/javadoc-api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29" rel="nofollow">http://static.springsource.org/spring/docs/3.0.0.RC1/javadoc-api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29</a><br />
<a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29" rel="nofollow">http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29</a><br />
<a href="http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29" rel="nofollow">http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/context/support/AbstractApplicationContext.html#getBeanFactory%28%29</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: abalyan</title>
		<link>http://www.javathinking.com/2009/06/no-scope-registered-for-scope-request/comment-page-1/#comment-1446</link>
		<dc:creator>abalyan</dc:creator>
		<pubDate>Mon, 09 Nov 2009 14:53:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.javathinking.com/?p=300#comment-1446</guid>
		<description>is context of type ApplicationContext? I can&#039;t find method getBeanFactory for it</description>
		<content:encoded><![CDATA[<p>is context of type ApplicationContext? I can&#8217;t find method getBeanFactory for it</p>
]]></content:encoded>
	</item>
</channel>
</rss>

