您的位置:首页 > 编程语言 > Java开发

springmvc+mybatis

2016-01-26 10:05 344 查看
这两天在学习springmvc+mybatis遇到一个问题,在服务器启动的时候一直报错

Invalid property 'sqlSessionFactoryBeanName' of bean class [org.mybatis.spring.mapper.MapperScannerConfigurer]: Bean property 'sqlSessionFactoryBeanName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return。。。。。

我的配置文件是<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<!-- 扫描包路径,如果需要扫描多个包,中间使用半角逗号隔开 -->

<property name="basePackage" value="com.ssm.mapper"/>

<!-- 这么写,注意!因为MapperScannerConigurer实际是在解析加载bean定义阶段的,这个时候要是设置sqlSessionFactory的话,

会导致提前初始化一些类,这个时候,PropertyPlaceholderConfigurer还没来得及替换定义中的变量,导致把表达式当作字符串复制了,

解决的办法如下:修改为

原理:使用sqlSessionFactoryBeanName注入,不会立即初始化sqlSessionFactory, 所以不会引发提前初始化问题,同时还应注意

在配置org.mybatis.spring.SqlSessionFactoryBean这个Bean时,id不能为sqlSessionFactory,如果为这样的话会导致

MapperScannerConigurer在bean定义加载时,加载PropertyPlaceholderConfigurer还没来得及替换定义中的变量 -->

<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />

查了好几个小时,网上说是jar包不对,jar包版本要一直,后来上网重新找的mybatis-3.2.3.jar、mybatis-3.2.3-sources.jar导入项目中,删去重复的jar包,重新启动,项目好使了。O(∩_∩)O哈哈~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: