spring多文件的几种配置步骤

spring多文件的几种配置方法
spring多配置文件在web.xml中的几种配置方式:
往往在实际的开发当中会涉及到许多的spring配置文件。那么这些配置文件应该如何在web.xml中配置呢?
<1>:
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/classes/applicationContext-*.xml,classpath*:application-*.xml</param-value>
</context-param>

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

<2>:
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
    /WEB-INF/classes/applicationContext.xml
/WEB-INF/classes/applicationContext2.xml
  </param-value>
</context-param>
<3>:
<beans>
  <bean id="default" class="org.springframework.context.support.ClassPathXmlApplicationContext">
    <constructor-arg>
      <list>
        <value>applicationContext.xml</value>
        <value>applicationContext-business.xml</value>
        <value>applicationContext-scheduler.xml</value>
      </list>
    </constructor-arg>
  </bean>
</beans>

然后在web.xml文件中,使用自己定义的ContextLoaderServlet来启动,这个ContextLoaderServlet可以继承HttpServlet,
在它inti()时候取得BeanFactory,代码如下:
public class ContextLoaderServlet extends HttpServlet {
  public ContextLoaderServlet() {}
  public init()  throws ServletException{
     //这个参数里的名字就是我们在BeanRefFactory.xml里定义的bean的名字。
DefaultBeanFactory.getFactory("default");
  }
  public destory() {}
}

然后定义一个DefaultBeanFactory类
public class DefaultBeanFactory () {
  proterced static final BeanFactory getFactory (String s) {
  BeanFactoryLocator beanfactorylocator = SingletonBeanFactoryLocator.getInstance();
  BeanFactoryReference beanfactoryreference = beanfactorylocator.useBeanFactory(s);
  return beanfactoryreference.getFactory();  
  }
}

最后在web.xml中的配置
最后在web.xml文件中配置如下:
<servlet>
  <servlet-name>context</servlet-name>
  <servlet-class>com.tks.web.servlet.ContextLoaderServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

上面所说的几种方式都可以用,根据自己的喜爱吧!说的有点仓促,呵呵!快下班了!今天就写到这里吧!
1 楼 chq32 2008-10-17  
在一个主spring配置文件中,import其它spring配置文件就行了
2 楼 hansonmo 2008-10-21  
chq32 写道
在一个主spring配置文件中,import其它spring配置文件就行了


同意!
3 楼 xo_tobacoo 2009-02-23  
四、    <beans>
        <import resource="billingServices.xml"/>
        <import resource="shippingServices.xml"/>
        <bean id="orderService"
            class="com.lizjason.spring.OrderService"/>
    <beans>


五、 String[] serviceResources =
        {"orderServices.xml",
        "billingServices.xml",
        "shippingServices.xml"};
    ApplicationContext orderServiceContext = new
        ClassPathXmlApplicationContext(serviceResources);