我在哪里可以找到示例applicationContext.xml文件

问题描述:

在Spring 3发行版中,有一个项目文件夹已打包在发行版中。该项目文件夹有可用的样本applicationContext.xml文件。但是,当我从here下载Spring 4发行版时,它不附带项目文件夹,我无法找到样本applicationContext.xml。我在哪里可以找到示例applicationContext.xml文件。我在哪里可以找到示例applicationContext.xml文件

您可以使用此进一步的信息检查here

下面样品含有配置如下:

  • 组分扫描基com.foo其思想为您的根文件夹。
  • 基本数据源定义。
  • 属性占位符文件(database.properties)
  • 本地化支持的消息源。

样品的applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://www.springframework.org/schema/c" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.1.xsd"> 

    <context:property-placeholder location="classpath:/database.properties" /> 
    <context:component-scan base-package="com.foo" /> 


    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
     <property name="driverClassName" value="${jdbc.driverClassName}" /> 
     <property name="url" value="${jdbc.url}" /> 
     <property name="username" value="${jdbc.username}" /> 
     <property name="password" value="${jdbc.password}" /> 
     <property name="initialSize" value="5" /> 
     <property name="maxActive" value="10" /> 
    </bean> 

    <bean id="messageSource" 
     class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <property name="basename" value="messages" /> 
    </bean> 

</beans> 
+0

顺便说一句,我们不需要ApplicationConetxt在春季4个.Annotations在那里做的所有工作。我面对THI问题,然后删除此文件“ApplicationConetxt”,它工作。 – Ankur 2017-02-09 21:41:44

+0

是的,这不是Spring的新功能,但很难在所有博客中找到可用的applicationContext.xml。 – erhun 2017-02-11 12:09:21

+2

另外,许多Spring项目都是使用像applicationContext.xml这样的xml文件编写的,所以在遇到这些时,学习这种传统格式是很好的。 – Mushy 2017-09-11 15:35:31