• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Class Loading ApplicationContext

Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I have a problem with my AOP subject's final project.

I need to do a little application that show's a code snippet with an error (for instance, something posted as a question on this forum), runs that class, shows what fails and then runs the same snippet but with the error corrected. After much bargaining, we got the teacher to let us actually load the .class files necessary to run the problem and the solution, which I've managed to do using the Java Reflection API. The problem is that many of these problems are Spring AOP's, and they need their applicationContext.xml file to run.

My question is: how can I tell the classes which I'm loading and running at runtime to use that XML file???

I hope I made myself clear. If not, please let me know.

Thanks in advance.
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hector,

Let me see if I understand your problem correctly: you have several beans A, B and C defined within your Spring config files (via dependency injection). At run time you need to load either those classes (via reflection) or at least another class D that makes use of these beans (D also uses DI for referencing A, B and C). If that�s the case then I should make you aware about at least one design decision that you might reconsider: because you�re violating the DI pattern probably spring is not the ideal framework to use with your project.
Having said that you still can overcome the issue you�re facing. However it will require little bit more refactoring and use the glue code pattern that Spring recomands for solving this kind of problems. You could read more here:


Finally I�d suggest you writing a new class that uses the "glue code" for loading the spring beans and finally have this class loaded via reflection. I personally did that seceral time to integrate frameworks that are not spring-aware and I�m personally using the org.springframework.context.access.DefaultLocatorFactory class:

    Bookmark Topic Watch Topic
  • New Topic