Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no <em>default-scope</em> Attribute defined in spring-beans.xsd file. But according To <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/beans/factory/config/BeanDefinition.html" rel="nofollow noreferrer">BeanDefinition</a> API</p> <blockquote> <p><strong>Extended bean factories might support further scopes</strong>. </p> </blockquote> <p>And <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/web/context/WebApplicationContext.html" rel="nofollow noreferrer">WebApplicationContext</a> - A extended ApplicationContext supports <em>request</em> scope</p> <blockquote> <p>Supported in addition to the standard scopes "singleton" and "prototype"</p> </blockquote> <p>So just make sense To use request scope when you have a WebApplicationContext. And if you want To register of all beans defined in WebApplicationContext as request scoped, <strong>you must define a BeanFactoryPostProcessor</strong></p> <pre><code>public class RequestScopedPostProcessor implements BeanFactoryPostProcessor { public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException { for(String beanName: factory.getBeanDefinitionNames()) { BeanDefinition beanDefinition = factory.getBeanDefinition(beanName); beanDefinition.setScope("request"); } } } </code></pre> <p>And do not forget register your BeanFactoryPostProcessor</p> <pre><code>&lt;bean class="RequestScopedPostProcessor"/&gt; </code></pre> <p>But keep in mind</p> <blockquote> <p>This method <strong>does not consider ancestor factories</strong>. It is only meant for accessing local bean definitions of this factory</p> </blockquote> <p>So The BeanFactoryPostProcessor defined above just overrides scope property whether your bean is defined in your WebApplicationContext</p> <p><strong>UPDATE</strong></p> <blockquote> <p>is there a way to then override <strong>some of the default "request" scoped beans to be singleton scope</strong> ?</p> </blockquote> <p>Again you should use The same BeanFactoryPostProcessor provided above. I am not sure but I Think The only way you can set up its scope is by using <em>beanDefinition.setScope</em> method. And <strong>There is a lot of useful methods you can retrieve information about any bean</strong>. See <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.html" rel="nofollow noreferrer">ConfigurableListableBeanFactory</a> such as</p> <ul> <li>getBeanNamesForType</li> </ul> <p>...</p> <pre><code>/** * Suppose Service is an interface * * And you want to define all of Service implementations as singleton */ String [] beanNameArray = factory.getBeanNamesForType(Service.class); for(String beanName: beanNameArray) { BeanDefinition beanDefinition = factory.getBeanDefinition(beanName); beanDefinition.setScope("singleton"); } </code></pre> <p>I hope It can be useful</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload