Question

My application has a lot of DataAccessObjects and I have to put them in my applicationContext.xml file like this:

<bean id="sourceOfferDAO" class="com.example.dao.OfferDAO">
    <constructor-arg ref="sourceDataSource" />
</bean>

I would like to know whether I can generate these entries based on a list of classes? Autowiring is not an option now.

Was it helpful?

Solution

Autowiring is precisely the recommended method for doing this.

If that's really not an option, a possible alternative would be to create your own annotations, and have a build-time step that processes classes with these annotations to generate the XML. Alternatively, you could just put the names of classes in a text file, and write code that just loops over the entries in that text file and spits out the needed XML. I'm not aware of anything like either of these though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top