user3272931 user3272931 - 11 months ago 82
Java Question

Spring load Implementation no xml

I have the next question, I have a SPRING app, with a configuration xml (no Spring), this document has the name of the class to implement in my app (lets said com.stack.impl.MyClass) and this classs implements my Interface (lets said MyInterface)
So I want to dinamically call the implementation when something happen, like this:

String myClass=xml.getProperty(id);
MyInterface myInterface=ctx.getBean(myClass);

Any sugestion? Thanks and regards


I used this method, thank alot for your help @duffymo and @jjhavokk, hope you get the same help from other ppl:

public AnnotationConfigApplicationContext init(){
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    try { 
        Class<DataPreProcessor> c= (Class<DataPreProcessor>) Class.forName("");
        Class<DataPreProcessor> c2= (Class<DataPreProcessor>) Class.forName("");
         DataPreProcessor dp=c.newInstance();
        DataPreProcessor dp2=c2.newInstance();
        context.getBeanFactory().registerSingleton("c", dp);
    } catch (InstantiationException e) {

    } catch (IllegalAccessException e) { 
    } catch (ClassNotFoundException e) { 
    return context;