通配符的匹配很全面, 但无法找到元素 ‘context:property-placeholder’ 的声明
在Spring配置文件中出现通配符的匹配很全面, 但无法找到元素 ‘context:property-placeholder’ 的声明这个错误,其实主要是我们在引入命名空间时没有正确引入它的DTD解析文件,当然你必须在把Spring相应的包导入正确的情况下。
解决方案就是如下:
xmlns:context=”http://www.springframework.org/schema/context”
同时在xsi:schemaLocation这个字符串中添加context相关的解析文件
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd。
其他的如util命名空间导入方式一样,只是把context换成相应util就可以了。
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for select * from tb_user where id = ?
Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for select * from tb_user where id = ?
基本的东西,在利用mybatis进行原始Dao开发的时候
其中利用SqlSession进行数据库查询的时候,其方法的参数应该写成图中方框内容,而我竟然写成了最基本的sql语句,所以报上述错误。。。
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class'${jdbc.driverClass}'
The error may exist in com/ssm/mapper/UserMapper.xml
The error may involve com.ssm.mapper.UserMapper.selectById
The error occurred while executing a query
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class ‘${jdbc.driverClass}’
在进行Spring和Mybatis整合的时候,我们在进行Mapper代理开发的时候,生成的Mapper代理对象需要在Spring容器中注册,有两种配置方式
一种是利用MapperFactoryBean,通过mapper工厂bean生成Mapper代理对象
需要向其中注入代理的mapper接口和会话工厂
<!--MapperFactoryBean继承了SqlSessionDaoSupport类-->
<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.ssm.mapper.UserMapper"/>
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
但是这种注册方式有个缺点,就是每需要一个代理我们就需要向Spring容器中注册,如果生成多个,难不成也要注册多个?
所以第二种方式的出现就是为了解决这个问题。批量扫描Mapper,为我们批量产生mapper代理
<!--通过MapperScannerConfigurer进行Mapper扫描-->
<!--mapper批量扫描,从mapper包中扫描mapper接口,自动创建动态代理对象并在Spring容器中注册
遵循规法:mapper.java和mapper.xml映射文件名保持一致,且在一个目录中
自动扫描出来的mapper的bean的id为mapper类名(首字母小写)
-->
<!--注意:此处的坑!!!!需要注入sqlSessionFactory,如果我们通过引用注入,则配置文件无法加载
所以我们通过设置sqlSessionFactoryBeanName来进行注入
-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--指定扫描的包名,如果有多个包,用,隔开-->
<property name="basePackage" value="com.ssm.mapper"/>
<!--<property name="sqlSessionFactory" ref="sqlSessionFactory"/>-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
如果sqlSessionFactory的注入我们利用了注释掉的方式,就会产生上述错误,也就是因为数据库的配置文件加载失败。
但是这是什么原因???有待研究