I have following class:
@Component("persistenceJPAConfig")
public class JPAPersistenceConfig {...}
Using Spring I am able to "inject" the class by adding a method with @Autowired-annotation in my target Class where I want to use JPAPersistenceConfig - Class. I works fine, the class itself is fine.
The Problem is that I have to create a Class at runtime (writing source code and compile it) that has to use the bean as well.
I added the autowired-methods too, but it keeps to be null.
@org.springframework.stereotype.Component("Customers")
public class Customers {
public Customers() {
}
private org.product.server.database.JPAPersistenceConfig persistenceJPAConfig;
@org.springframework.beans.factory.annotation.Autowired
public void setPersistenceJPAConfig(org.product.server.database.JPAPersistenceConfig persistenceJPAConfig) {
this.persistenceJPAConfig = persistenceJPAConfig;
}
public void someMethod() {
this.persistenceJPAConfig.getClassByName(...)
// Throws nullpointer
}
}
Do I have to mark the generated file with @Component too so that it becomes a "managed bean" in Spring? And how is it registered in Spring at runtime?
desperately yours :-)