求各位大神指点,学习搭建框架 ,拜托了 !!!!!急急急 Struts2,spring,mybatis 框架集成遇到的 sqlSessionFactory问题
把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>
Error create bean with name “sqlSessionFactory”这一句整个贴出来
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.
应该是是用于设置你的dao和mabatis的sql语句映射文件的
写*。xml就可以把你的dao的mapper配置的xml引入。前面是你放你的mapper xml的包的路径
其实你还可以这么配置
<!-- 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
It should be JdbcType.VARCHAR but not JdbcType.varchar, case sensitive