context:property-placeholder标签无效

公司老的SpringMVC项目加入MyBatis多数据源,引入jdbc.properties时出现报错。报错信息为找不到'context:property-placeholder'元素声明,解决方法是在文件头引入特定命名空间,并在xsi:schemaLocation中添加context相关解析文件。

公司老的springmvc项目加入mybatis多数据源的东西,mybatis.xml引入jdbc.properties,

<context:property-placeholder location="classpath:jdbc.properties" />

报错:The matching wildcard is strict, but no declaration can be found for element  'context:property-placeholder'.

解决方法:

  1. 在文件头中引入:xmlns:context="http://www.springframework.org/schema/context"

  2. 在xsi:schemaLocation这个字符串中添加context相关的解析文件 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.2.xsd。

<?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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 加载db.properties --> <context:property-placeholder location="classpath:db.properties"/> <!-- 数据源配置 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- MyBatis SqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- 指定MyBatis配置文件 --> <property name="configLocation" value="classpath:mapper/mybatis-config.xml"/> <!-- 指定mapper.xml文件位置 --> <property name="mapperLocations" value="classpath:mapper/*.xml"/> </bean> <!-- Mapper扫描配置 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.ssm.dao"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> <!-- 事务管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- 组件扫描 --> <context:component-scan base-package="com.ssm.service,com.ssm.aop"/> </beans>无法解析 文件 'mybatis-config.xml'解决一下
最新发布
06-07
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值