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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top