Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder ‘path’ in value “${path}”
此错误的意思可以理解无法将配置文件中的path的值导入。
造成此错误的原因有多种,我把我所遇到的问题及解决方法交待一下。
对outPutPath注入报错
查看配置文件(没有问题)
spring-service.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:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--加载属性文件,后期在java代码中会使用到属性文件中定义的key-> value-->
<!-- 指定应用名称-->
<dubbo:application name="shiyitiancheng_health_service_provider"/>
<!-- 指定暴露服务的端口,如果不指定默认为20880-->
<dubbo:protocol name="dubbo" port="20887"/>
<!-- 指定服务注册中心地址-->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- 批量扫描,发布服务-->
<dubbo:annotation package="com.shiyitiancheng.service"/>
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<!--指定模板文件所在目录-->
<property name="templateLoaderPath" value="/WEB-INF/ftl/" />
<!--指定字符集-->
<property name="defaultEncoding" value="UTF-8" />
</bean>
<!--加载属性文件,后期在java代码中会使用到属性文件中定义的key和value-->
<context:property-placeholder location="classpath:freemarker.properties"/>
</beans>
注意: <context:property-placeholder location=“classpath:***”/>使用时同一模块不要多个使用
我的spring-dao.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.xsd">
<!-- 在同一模块中用了两次 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource" destroy-method="close">
<property name="username" value="${jdbc.username}"/>
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}?characterEncoding=UTF-8"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:SqlMapConfig.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.shiyitiancheng.dao"/>
</bean>
</beans>
两个xml文件中都用了<context:property-placeholder location=""/>*
结果导致如下情况
解决方法:只在一个文件中使用且只使用一次<context:property-placeholder location="**"/>想导入多个配置文件可使用通配符‘*’代替
我在spring-dao.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.xsd">
<!-- 在同一模块中只能使用一次 -->
<context:property-placeholder location="classpath:*.properties"/>
<bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource" destroy-method="close">
<property name="username" value="${jdbc.username}"/>
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}?characterEncoding=UTF-8"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:SqlMapConfig.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.shiyitiancheng.dao"/>
</bean>
</beans>
在spring-service.xml中删除了<context:property-placeholder location=“classpath:freemarker.properties”/>
运行正常