2 qq 24527781 qq_24527781 于 2016.09.10 11:35 提问

集成框架,遇到SQLSessionFactory的相关问题 ,求哪位大神帮帮忙,拜托了!!! 6C

图片说明求各位大神指点,学习搭建框架 ,拜托了 !!!!!急急急 Struts2,spring,mybatis 框架集成遇到的 sqlSessionFactory问题

7个回答

z1729734271
z1729734271   2016.09.10 11:59

把applicationContext.xml文件贴出来看看

qq_24527781
qq_24527781 帮忙看下
大约一年之前 回复
qq_24527781
qq_24527781   2016.09.10 12:03

以下是applicationContext.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"

>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">   
 <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
 <property name="url" value="jdbc:oracle:thin:@localhost:1521:MYBASESON"/>
 <property name="username" value="KING"/>
 <property name="password" value="123" />
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"/>
  <property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>


<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="www.hg.dao.UserDao" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>


<bean id="userService" class="www.hg.service.Impl.UserServiceImpl">
     <property name="userDao" ref="userMapper" />
</bean>

<bean name="userAction" class="www.hg.web.UserAction" scope="prototype">
          <property name="userService" ref="userService"></property>
</bean>

markbug
markbug   2016.09.10 13:54

Error create bean with name “sqlSessionFactory”这一句整个贴出来

markbug
markbug QQ897391595
大约一年之前 回复
qq_24527781
qq_24527781   2016.09.10 16:34

Error creating bean with name 'sqlSessionFactoryBeanName' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.varchar
at org.springframework.beans.factory.support.

qq_35124119
qq_35124119   2016.09.10 22:31

应该是是用于设置你的dao和mabatis的sql语句映射文件的
写*。xml就可以把你的dao的mapper配置的xml引入。前面是你放你的mapper xml的包的路径

qq_35124119
qq_35124119   2016.09.10 22:36

其实你还可以这么配置

<!-- DAO接口所在包名,Spring会自动查找其下的类 -->  
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <!-- 值是你的dao接口所在包的路径-->  
    <property name="basePackage" value="com.cn.hnust.dao" />  
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
</bean>  

    这样的话spring会创建你的dao接口的实现类对象,直接通过注解注入你的Dao 就可以调用你dao接口的方法,而不用去管sqlSessionFactory,底层跟你写的userMapper的bean是一样的,只是spring自动完成  

    当然 如果你的dao接口比较少的话 你也可以想你的userMapper那样每个dao配置一个bean
zealVampire
zealVampire   2016.09.13 10:55

It should be JdbcType.VARCHAR but not JdbcType.varchar, case sensitive

Csdn user default icon
上传中...
上传图片
插入图片