Spring的配置文件applicationContext.xml理解

Spring的配置文件十分重要。学习框架的过程中主要就是配置。IOC和AOP都依赖于spring的配置文件。一般我们起名叫做applicationContext.xml。(因为会用到这个类加载配置文件)。

它的位置,一般建议放到src同级目录下。若放到其他目录下,其他路径需自行更改。其次它需要有一定的规约。

在项目开发IDE中,看到如下的xml文件

Spring的配置文件applicationContext.xml理解

其实一般用到的时候度娘一搜,直接copy就行了。但是具体的意思是:

1.)xmlns=http://www.springframework.org/schema/beans

     声明xml文件默认的命名空间,表示未使用其他命名空间的所有标签的默认命名空间。

2.)xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance

     声明XML Schema实例,辅助初始化bean,声明后可以使用schemaLocation属性

3.)

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

这个属性有两个值,第一个值表示需要使用的命名空间。第二个值表示供命名空间使用的XML schema的位置。


ps:解决MyEclipse配置xml时候不提示的方法:

window-->preference-->

Spring的配置文件applicationContext.xml理解

选择add或者edit

Spring的配置文件applicationContext.xml理解

要和这个一致

Spring的配置文件applicationContext.xml理解


最后关闭重新打开xml文件,就有提示内容了。。