Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder ‘**‘* in value “${***}

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”/>

运行正常

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值