Giter Site home page Giter Site logo

spring-scopes's Introduction

spring-scopes

Custom Spring Bean Scopes for those situations where the defaults just won't do

Available Scopes

  • Route Scope - Scope providing per-route-execution scoping
  • Page Scope - Scope providing per-page scoping
  • Thread Scope - Scope providing per-thread scoping
  • Inherited Thread Scope - Scope providing per-thread-and-child-thread scoping

In order to use custom scopes you must register the scope with Spring. This can be done via Java Config or XML Config as shown below. In both examples, the scope-name string should be replaced with the string you will use to reference that scope and the CustomScope class should be the class of the scope you are adding.

Java Config Example

@Configuration
public class ScopeConfig {

    @Bean
    public CustomScopeConfigurer customScopeConfigurer() {
        CustomScopeConfigurer configurer = new CustomScopeConfigurer();

        Map<String,Object> scopes = new HashMap<String,Object>();
        scope.put("scope-name",new CustomScope());

        configurer.setScopes(scopes);
        return configurer;
    }
}

XML Config Example

<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
  <property name="scopes">
    <map>
      <entry key="scope-name"><bean class="com.example.CustomScope"/></entry>
    </map>
  </property>
</bean>

Route Scope

Scope a bean by a route's execution. Beans are bound by the initial exchange and maintained even through splits and aggregations.

In order to use Page Scope, you must register the scope with Spring's CustomScopeConfigurer and then register the notification service. This service manages setting the Exchange context

<bean id="exchange-scope-event" class="com.jyore.spring.scope.route.ExchangeEventNotifier"/>

Page Scope

The page scope allows per-page or even per-page-and-page-parameters scoping. This type of scoping could be useful when needing to provide per-page static or semi-static data caching (i.e. JSON data). It could also be used to manage a page that is being edited by multiple users simultaneously (i.e. Google Docs).

In order to use Page Scope, you must register the scope with Spring's CustomScopeConfigurer and also register the PageScopeFilter in your servlet filter chain (i.e. in your web.xml or configure with Spring).

Thread Scope

The thread scope simply scopes beans per-thread. With this scope, brean creation is done per thread. NOTE: Children threads will get new beans

Inherited Thread Scope

The inherited thread scope simply scopes beans per-thread. With this scope, brean creation is done per thread. If a thread spawns children threads, they will also be covered in the scope

spring-scopes's People

Contributors

jyore avatar

Watchers

James Cloos avatar Jason avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.