昨天自己搭建了一个ssm项目,配上aop日志管理,没想到太长时间没重新搭建框架,出现了一些问题,在这里记录下来。
我目前的问题是:在spring-mybatis.xml中
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:rtm/fire/system/mapping/*.xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="rtm.fire.system.IDao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>报一个
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.mapper.MapperScannerConfigurer#0' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'initialSize'; nested exception is java.lang.NumberFormatException: For input string: "${jdbc.initialSize}"
错误,首先是检查jdbc存放的值是不是有问题,但是一看没问题,然后baidu,看到大部分都说是这个存放参数的路径找不到导致的,经过确认还不是,之后我就想到可能是重名的问题,
先告诉大家这个的解决方法:
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactoryupdate" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:rtm/fire/system/mapping/*.xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="rtm.fire.system.IDao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryupdate"></property>
</bean>然后说明原因:
在spring中如果扫描MapperScannerConfigurer的时候,会因为要加载sqlSessionFactoryBeanName,而提前使用那些参数,在使用的时候这些参数还没有被注入进来,就报了上面的错误,提示把它当成字符串加载了,如果设置sqlSessionFactory就会优先加载那些类
一句话总结就是防止:初始化SqlSessionFactoryBean在placeHolder之前
好了,我之后还会发一篇,如果有空可以去看看
209

被折叠的 条评论
为什么被折叠?



