Results 1 to 6 of 6

Thread: Every object throught Spring. Spring as univerzal factory.

  1. #1
    Join Date
    Apr 2006
    Posts
    12

    Default Every object throught Spring. Spring as univerzal factory.

    Can I use spring as universal factory for every class?

    I know how to use spring as factory for predefined bean (by annotation or in XML descriptor). But I don't know haw use spring when I want create instance of another class?

    In spring I define AOP advice etc. But this advice is apply through proxy only on bean create by spring factory.

    I want use spring factory instead of "new Something()"
    ------------------------------------------------------------
    I use XEmacs + JDEE, Spring, Hibernate and special benzin's fork of English.

  2. #2
    Join Date
    Aug 2008
    Location
    Lodz, Poland
    Posts
    47

    Default

    Use AspectJ with bytecode modification and @Configurable, then you can create new instances using "new Something()" and they will be configured by Spring. You will find details in Spring documentation.

  3. #3
    Join Date
    Apr 2006
    Posts
    12

    Default

    Quote Originally Posted by grzegorzborkowski View Post
    Use AspectJ with bytecode modification and @Configurable, then you can create new instances using "new Something()" and they will be configured by Spring. You will find details in Spring documentation.
    I know this purpose and now I use it, but I dislike this solution, because of compile time waving change number of rows and then is hard to find place of exception origin.
    ------------------------------------------------------------
    I use XEmacs + JDEE, Spring, Hibernate and special benzin's fork of English.

  4. #4
    Join Date
    Aug 2008
    Location
    Lodz, Poland
    Posts
    47

    Default

    Well, I've never faced this problem... perhaps you should switch to load time waving? At least during debugging.

  5. #5
    Join Date
    Apr 2006
    Posts
    12

    Default

    Quote Originally Posted by grzegorzborkowski View Post
    Well, I've never faced this problem... perhaps you should switch to load time waving? At least during debugging.
    I user jetty server and I can't use LTW with this server . I try agent because I can use java 1.6 but this not run for me same as custom class loader.

    But when I can use spring as univerzal factory I needn't LTW or compile time waving. I this this is best way for me.
    ------------------------------------------------------------
    I use XEmacs + JDEE, Spring, Hibernate and special benzin's fork of English.

  6. #6
    Join Date
    Aug 2008
    Location
    Lodz, Poland
    Posts
    47

    Default

    Spring is not a virtual machine nor some magic "universal factory". It's DI container/framework. Also I'm not sure how you plan to use such solution. Would you like to ask application context to create new instance of given class, passing class name? By default Spring needs all the metadata for beans at startup time (at least I think so), so you would have to configure them in XML or some different way first. (Perhaps you can extend it somehow to be able to read bean metadata on the fly, when you ask for new bean types - if you need it... but I'm not sure if it's possible and how difficult it would be).
    But anyway in your approach you would have to pass the same application context reference to every place where you want to instantiate new class. This it not a good design pattern IMHO.

Posting Permissions

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