今天给大家详细解释一项关于Spring的applicationContext.xml文件,这对于初学者来说,应该是很有帮助的,
以下是详解Spring的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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- 注解模式的使用,必须进行扫包 -->
<context:component-scan base-package="com.yw.*"></context:component-scan>
<!-- 引入jdbc.property -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据库连接池 -->
<bean > 引用mybaits的config文件 -->
<!--第一种引入方式,也就是最原始的方法,首先将映射文件引入mybatis的配置文件中,然后再将配置文件引入进来-->
<!-- <property name="configLocation" value="classpath:mybatis.xml" /> -->
<!--也可以直接引入mybatis的mapping文件 name的值不是configurationProperties,而是mapperLocations 这样引入了就不会给实体取别名了 -->
<!--第二种方式,直接将映射文件引入进来,这样就不能给实体取别名了,-->
<!-- <property name="mapperLocations" value="classpath:com/yw/entity/*.xml"/> -->
<property name="mapperLocations" value="classpath:com/yw/entity/jianfusingle.xml"/>
</bean>
<!-- 获取sqlSesion的对象 --><!-- 创建sqlsession时不忘了scope="prototype" -->
<bean />
</bean>
</beans>