spring指定加载配置文件的两种方式

标题通过file关键字指定文件在物理绝对路劲

注意这里的file后面有一个:,上次我遗漏,然后找了半天…

		<bean id="configProperties"
		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
		<property name="locations">
			<list>
				<value>File:/home/paydubbo/etc/config.properties
				</value>
			</list>
		</property>
	</bean>

通过classpath:指定相对路劲

<bean id="configProperties"
		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
		<property name="locations">
			<list>
				<value>classpath:config.properties
				</value>
			</list>
		</property>
	</bean>

springboot中通过注解导入xml配置文件

@Configuration
@ImportResource(value = {"classpath:spring-context.xml"})
@ImportResource(value = "file:${workdir}/config/spring-context.xml")

猜你喜欢

转载自blog.csdn.net/u010316188/article/details/83069218