【问题标题】:XML files needed to configure Spring application配置 Spring 应用程序所需的 XML 文件
【发布时间】:2011-09-13 00:16:30
【问题描述】:

想知道配置Spring XML配置文件的最佳实践

1- 我应该有多少个配置文件? 2- 每个文件的内容。

现在,根据一些教程,我的 Spring 应用程序有 3 个 xml 配置文件:

1- app-config.xml:包含propertyPlaceholder配置,hibernate配置,以及后续注解配置。

<context:component-scan base-package="com.spring.sample" />

    <!-- declares support for general annotations such as @Required, @Autowired,         @PostConstruct -->
    <context:annotation-config />

    <!-- enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="transactionManager" />

2- mvc-config.xml:包含注解支持标签、messageSource配置、mvc拦截器和localResolver

3- servlet-config.xml:其中包含jsp的viewResolver,以及以下标签:

<context:component-scan base-package="com.spring.sample.controller"/>

【问题讨论】:

    标签: spring spring-mvc


    【解决方案1】:

    看到这个答案。 Spring Configuration

    你的布局很好,答案会解释我为什么使用类似的。

    【讨论】:

    • 不错的帖子,但我有两个问题:1- 你为什么在这里使用 *:contextConfigLocationclasspath* :META-INF/spring/applicationContext*.xml 2-为什么要在 DispatcherServlet 中使用标签 1
    • 1:因为我经常将项目拆分为不同的罐子。 2 哦,它似乎是来自旧应用程序的左 ovet 或 spring roo 默认值。 - 没有我的电脑,我无法回答这个问题。 (我在度假,只有我的智能手机)
    猜你喜欢
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-23
    相关资源
    最近更新 更多