我们知道,有时候在xml配置文件中需要引入外部配置文件变量,在这里有两种情况:
第一种是我是在写generatorConfig.xml文件的时候,这是mybatis-genearator配置生成pojo,mapper的配置文件,写法如下:
<generatorConfiguration>
<!-- 引入配置文件 -->
<properties resource="jdbc.properties"/>
. ........
........
........
</generatorConfiguration>
第二种是我在配置spring的applicationContext.xml文件的时候,这是spring的一个重要配置文件,其中配置数据源时如何采用外部引入的方法,引入
jdbc,.properties文件,有两种方法:
方法1:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/main/resources/jdbc.properties"></property>
</bean>
需要注意的是,当前location路径是以src为根路径的,否则会报:
Could not open ServletContext resource [/jdbc.properties]
方法2:
<context:property-placeholder location="classpath:jdbc.properties" />
这里只需如此配置。
·