记录一个错
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'url' in value "${url}"
发生错误原因
applicationContext-dataSource.xml中引入配置
<context:property-placeholder location="classpath:jdbc.properties"/>
applicationContext.xml中配置
<import resource="applicationContext-datasource.xml"/>
<!-- <import resource="applicationContext-dubbo.xml"/>-->
<!-- <import resource="applicationContext-apollo.xml"/>-->
<!-- <import resource="applicationContext-rpc.xml"/>-->
<context:property-placeholder location="classpath:config.properties"/>
<context:component-scan base-package="com.travel.background.Configuration"/>
<bean class="com.travel.background.Configuration.ConfigurationBeanTest">
<property name="url" value="${url}"/>
<property name="path" value="${path}"/>
</bean>
将配置改为
删除applicationContext-dataSource.xml中引入配置的代码
在applicationContext.xml中修改配置
<import resource="applicationContext-datasource.xml"/>
<import resource="applicationContext-dubbo.xml"/>
<import resource="applicationContext-apollo.xml"/>
<import resource="applicationContext-rpc.xml"/>
<context:property-placeholder location="classpath:config.properties,classpath:jdbc.properties"/>
<context:component-scan base-package="com.travel.background.Configuration"/>
<bean class="com.travel.background.Configuration.ConfigurationBeanTest">
<property name="url" value="${url}"/>
<property name="path" value="${path}"/>
</bean>
本文详细解析了在Spring框架中因属性占位符配置不当导致的IllegalArgumentException异常,并提供了具体的解决方案,包括调整配置文件的引用方式和位置,确保属性正确加载。
1785

被折叠的 条评论
为什么被折叠?



