applicationContext.xml为我们常用的spring配置文件。
其中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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"
default-lazy-init="true">
</beans>
其实,你可以理解这些是格式性文件,只有引入了.xsd才能用其中的标签,用alt+ /回头提示。
xsd里面的标签里面有子标签
比如aop的配置,只能用下面的几个配置
<aop:config><aop:advisor advice-ref=""/></aop:config>
<aop:config><aop:aspect></aop:aspect></aop:config>
<aop:config><aop:pointcut expression="" id=""/></aop:config>
对应的xsd 如下:
-<xsd:element name="config">
-<xsd:annotation>
-<xsd:documentation>
-<![CDATA[
A section (compartmentalization) of AOP-specific configuration (including
aspects, pointcuts, etc).
]]>
</xsd:documentation>
</xsd:annotation>
-<xsd:complexType>
-<xsd:sequence>
-<xsd:element name="pointcut" maxOccurs="unbounded" minOccurs="0" type="pointcutType">
-<xsd:annotation>
-<xsd:documentation>
-<![CDATA[
A named pointcut definition.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
-<xsd:element name="advisor" maxOccurs="unbounded" minOccurs="0" type="advisorType">
-<xsd:annotation>
-<xsd:documentation source="java:org.springframework.aop.Advisor">
-<![CDATA[
A named advisor definition.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
-<xsd:element name="aspect" maxOccurs="unbounded" minOccurs="0" type="aspectType">
-<xsd:annotation>
-<xsd:documentation>
-<![CDATA[
A named aspect definition.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
你可以理解他就是定义格式的文件,我spring只能配置这些格式。
软件有一句话,约定优于配置,人家约定好了,你照着做就行。