Announcement Announcement Module
Collapse
No announcement yet.
Every object throught Spring. Spring as univerzal factory. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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()"

  • #2
    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.

    Comment


    • #3
      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.

      Comment


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

        Comment


        • #5
          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.

          Comment


          • #6
            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.

            Comment

            Working...
            X