spring配置文件关系? [英] spring configuration files relationship?

查看:122
本文介绍了spring配置文件关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是spring3.x。我在我的应用程序中有以下配置文件。

I am using spring3.x. i have below configuration files in my application.

applicationContext.xml
spring-ws-servlet.xml



web.xml



web.xml

   <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:config/applicationContext.xml</param-value>
    </context-param>


<servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
            <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:config/spring-ws-servlet.xml</param-value>
        </init-param>

    </servlet>
    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

我的问题是我们需要在 applicationContext中保留哪种bean。 xml 以及我们需要在 spring-ws-servlet.xml 中保留哪种bean?为什么我们需要两者?我应该将所有内容保存在 applicationContext.xml 中并删除 spring-ws-servlet.xml

My question is what kind of beans do we need to keep in applicationContext.xml and what kind of beans do we need to keep in spring-ws-servlet.xml ? why do we need both? Shall i keep everything in applicationContext.xml and delete spring-ws-servlet.xml ?

如果我有两个,那么我应该在另一个中导入吗?请帮助我。

If i have both then should i import one in another ? Please help me.

谢谢!

推荐答案

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:config/applicationContext.xml</param-value>
</context-param>

您必须将监听器定义为:

You must have a listener defined as this:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

ContextLoaderListener 监听器负责启动和停止Spring root ApplicationContext 接口,该接口加载 applicationContext.xml 中定义的bean。它通过查看 contextConfigLocation < context-param> 标记来查找要使用的配置。

This ContextLoaderListener listener is responsible for starting and stopping the Spring root ApplicationContext interface, which loads the beans defined in applicationContext.xml. It finds the configurations to be used by looking at the <context-param> tag for contextConfigLocation.

<servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
            <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:config/spring-ws-servlet.xml</param-value>
        </init-param>
</servlet>

由<$ c $创建的 ApplicationContext c> DispatcherServlet 是 root ApplicationContext 接口的子代。 通常,Spring MVC特定组件
在DispatcherServlet的ApplicationContext接口中初始化,而
其余由 ContextLoaderListener

The ApplicationContext created by DispatcherServlet is a child of the root ApplicationContext interface. Typically, Spring MVC-specific components are initialized in the ApplicationContext interface of DispatcherServlet, while the rest are loaded by ContextLoaderListener.

子ApplicationContext 中的bean(例如由DispatcherServlet创建的bean)可以引用其父ApplicationContext的bean (例如ContextLoaderListener创建的那些)。但是,父ApplicationContext 无法引用子ApplicationContext的bean

The beans in a child ApplicationContext (such as those created by DispatcherServlet) can refer to beans of its parent ApplicationContext (such as those created by ContextLoaderListener). However, the parent ApplicationContext cannot refer to beans of the child ApplicationContext.

这篇关于spring配置文件关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆