Results 1 to 2 of 2

Thread: Custom scope and singleton

  1. #1
    Join Date
    Dec 2005
    Posts
    6

    Default Custom scope and singleton

    I have a custom scope created for a web app context. I call it 'application' scope, beans get directly stored in servletContext under their specified ID. The reason for this is because we have applications that don't use Spring that will be converted to use it and they expect to be able to get at the beans in the servletContext, so this helps with porting.

    My question is, how can I have the beans specified with custom scope and get created when the app context is created (like a Singleton)?

    Any suggestions?

    Thanks,
    Bill.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Why does it have to be an extra scope?

    Wouldn't it be easier to create a BeanPostProcessor which (after creation of the bean) registers it also in the ServletContext? That way your beans still are singletons, no fiddling around with custom scopes.

    Even better Spring already provides that, check out ServletContextAttributeExporter.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •