• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can spring change class dynamatically?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Such as add a method , a field at runtime stage on a web application.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, Java doesn't let you do this, so Spring won't either.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, you can with Spring AOP.

It is called Introductions, and here is a link to the docs that shows how to do this

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-introductions

Mark
 
Kurt Xu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Actually, you can with Spring AOP.

It is called Introductions, and here is a link to the docs that shows how to do this

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-introductions

Mark



To be exact, introduction need to be done at compilation time ,not runtime, cause at that moment ,bean has been created.

thanks.
 
Ranch Hand
Posts: 88
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well some byte code manuplation apis are availble like Javassist.
But, I am still interested why AOP will not work in your case.
Have you really read the concept? Don't mind its just I am big fan of spring AOP.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Actually, you can with Spring AOP.

It is called Introductions, and here is a link to the docs that shows how to do this

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-introductions

Mark



Hi, actually I don't believe IntroductionInterceptor can change class dynamically. I think it can intercept and add additional features that the original Java class doesn't have. I posted a question regarding this. Check it out and see if it's your case or not:

How to use IntroductionInterceptor...
 
Kurt Xu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shashank Ag wrote:Well some byte code manuplation apis are availble like Javassist.
But, I am still interested why AOP will not work in your case.
Have you really read the concept? Don't mind its just I am big fan of spring AOP.


well, javassist can't change class behavior after they are created, but that's exactly what I need.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These introduction methods are added to the code via AOP/Proxies and are created at runtime, not a special compile time thing to do. Spring AOP creates DynamicProxies at runtime.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic