aspose file tools
The moose likes Spring and the fly likes Can spring change class dynamatically? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Reply Bookmark "Can spring change class dynamatically?" Watch "Can spring change class dynamatically?" New topic
Author

Can spring change class dynamatically?

Kurt Xu
Ranch Hand

Joined: Sep 29, 2009
Posts: 32
Such as add a method , a field at runtime stage on a web application.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

No, Java doesn't let you do this, so Spring won't either.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17234
    
    1

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kurt Xu
Ranch Hand

Joined: Sep 29, 2009
Posts: 32
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.
Shashank Ag
Ranch Hand

Joined: Dec 22, 2009
Posts: 88

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.


SCJP 91%, SCWCD 97%
Bang Nguyen
Greenhorn

Joined: Feb 03, 2009
Posts: 15
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...


http://trongbang86.blogspot.com
http://twitter.com/trongbang86
Kurt Xu
Ranch Hand

Joined: Sep 29, 2009
Posts: 32
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
Sheriff

Joined: Feb 05, 2001
Posts: 17234
    
    1

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Can spring change class dynamatically?