欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ssm框架集成时,在spring配置文文件中集成mybatis时,在sqlSessionFactory中的属性configuration配置日志出错

程序员文章站 2022-07-15 10:59:59
...
[localhost-startStop-1] WARN org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDaoImpl' defined in file [E:\ideaproject\raky-code\user-ssm\target\classes\raky\train\dao\impl\UserDaoImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-context.xml]: Cannot create inner bean 'org.apache.ibatis.session.Configuration#6683523f' of type [org.apache.ibatis.session.Configuration] while setting bean property 'configuration'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.ibatis.session.Configuration#6683523f' defined in class path resource [spring-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.web.context.support.StandardServletEnvironment' to required type 'org.apache.ibatis.mapping.Environment' for property 'environment'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.web.context.support.StandardServletEnvironment' to required type 'org.apache.ibatis.mapping.Environment' for property 'environment': no matching editors or conversion strategy found
{dataSource-1} closing ...
{dataSource-1} closed
[localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDaoImpl' defined in file [E:\ideaproject\raky-code\user-ssm\target\classes\raky\train\dao\impl\UserDaoImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-context.xml]: Cannot create inner bean 'org.apache.ibatis.session.Configuration#6683523f' of type [org.apache.ibatis.session.Configuration] while setting bean property 'configuration'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.ibatis.session.Configuration#6683523f' defined in class path resource [spring-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.web.context.support.StandardServletEnvironment' to required type 'org.apache.ibatis.mapping.Environment' for property 'environment'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.web.context.support.StandardServletEnvironment' to required type 'org.apache.ibatis.mapping.Environment' for property 'environment': no matching editors or conversion strategy found

下面是spring+mybatis的配置文件内容

	<!-- 扫描包 -->
	<context:component-scan base-package="raky.train" >
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>

	<!--导入连接池配置文件-->
	<import resource="spring-druid.xml"/>



	<!--集成mybatis框架-->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:mybatis-config.xml" />
		<property name="typeAliasesPackage" value="raky.train.entity" />
<!--		<property name="mapperLocations" value="classpath*:mybatis/*.xml" />-->
		<property name="configuration" >
			<bean class="org.apache.ibatis.session.Configuration">
				<!--                配置驼峰式命名-->
				<property name="mapUnderscoreToCamelCase" value="true"/>
				<!--                配置日志-->
				<property name="logImpl" value="org.apache.ibatis.logging.log4j.Log4jImpl"/>
			</bean>
		</property>

	</bean>

	<!--5.配置sqlSessionTemplate-->
	<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" />
	</bean>
 
 	<!-- 配置事务管理 -->  
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>   
   
    <!-- 配置事务通知 -->
    <!-- 定义不同的方法使用不同的事务处理 -->
  	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="insert*" />
			<tx:method name="update*" />
			<tx:method name="delete*" />
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>
   
    <!-- 配置aop事务 -->
    <aop:config>
		<aop:pointcut id="txPointcut" expression="execution(* raky.train.service.*Service.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />
	</aop:config>

下面是springmvc的配置文件

 <!-- 开启注解 -->
   <mvc:annotation-driven />  
      
   <!-- 扫描包 -->
   <context:component-scan base-package="raky.train" >
       <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
   </context:component-scan>
   
   <!-- 视图解析器 -->
   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name = "prefix" value="/" /><!-- 前缀 -->
       <property name = "suffix" value = ".jsp" /><!-- 后缀 -->
   </bean>

这里的配置文件只复制了核心的部份
问题就是配置日志那块,删了就不会报错,在mybatis-config.xml文件中配置好再引用也不会报错,就是spring+mybatis集成的时候,在里面直接配置就会报上面的错误,不知道为什么。另外我在另一个项目,相同的配置,相同的pom,xml文件,使用集成的方法也不会出错,两相对比,基本上都一样,到底是为什么会报错呢?