简体   繁体   English

有没有一种方法可以为Spring生成applicationContext.xml?

[英]Is there a way to generate applicationContext.xml for Spring?

My application has a lot of DataAccessObject s and I have to put them in my applicationContext.xml file like this: 我的应用程序有很多DataAccessObject ,我必须将它们放在我的applicationContext.xml文件中,如下所示:

<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. 如果确实不可行,则可能的替代方法是创建您自己的注释,并具有一个构建时步骤,该步骤将处理带有这些注释的类以生成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. 或者,您可以只将类的名称放在文本文件中,然后编写代码,该代码仅循环遍历该文本文件中的条目并吐出所需的XML。 I'm not aware of anything like either of these though. 我什么都不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM