I’m curious as to whether one can define a Java class purely using a Spring configuration, and then probably create a bean from it too.
I.e, usually one would have
<bean id="mybean" class="com.my.existing.Klass" />
But this means you would need a Klass.java file that defines this class. Is it possible to give a bean a fully qualified class name and define its getters and setters using properties (so that this class is generated during compile time or something)?
UPDATE:
I decided to provide an example. Assume you have a simple struct that is essentially just a data carrier:
class Person {
public String name;
public Long id;
public Person(String name, Long id) {
this.name = name;
this.id = id;
}
}
To instantiate this using Spring, you would have:
<bean id="somePerson" class="mypackage.Person">
<property id="name" value="John Smith" />
<property id="id" value="1234" />
</bean>
If you wanted to make changes to this structure, you have to do it in two places. What if you can simply generate the class from the XML? Sure, it might require some extra info such as the classes to use for the properties, but that could be provided as an attribute.
I believe org.apache.commons.beanutils.DynaBean is what you are looking for, it is not Spring.