ApplicationContext ac = new ClassPathXmlApplicationContext("config/spring-mvc.xml"); SqlMapClientTemplate smct = (SqlMapClientTemplate) ac.getBean("sqlMapClientTemplate"); public class BehaviorDaoImpl{ public void saveUBD(){ smct.insert("saveprimaryUBD",subd); } } spring-mvc配置文件如下: <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-autowire="byName" > <!-- spring注解 --> <context:annotation-config /> <!-- <context:component-scan base-package="com.founder.ec" /> --> <!-- Ibatis SqlMap --> <!-- 连接对象 --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean" > <property name="configLocation" value="classpath:config/sqlMap.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <!-- 连接对象模板 --> <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" > <property name="sqlMapClient" ref="sqlMapClient" /> </bean> <!-- 数据源 --> <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" > <property name="driver"> <value>com.mysql.jdbc.Driver</value> </property> <property name="driverUrl"> <value>jdbc:mysql://localhost:3306/user_behavior_data</value> </property> <property name="user"> <value>root</value> </property> <property name="password"> <value>zxc123</value> </property> </bean> </beans> sqlMap.xml配置文件如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 指定映射器路径 --> <mappers> <mapper resource="sql/ubd.xml" /> </mappers> </configuration> ubd.xml配置文件如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> <mapper namespace="com.founder.ec.dao.impl.BehaviorDaoImpl"> <insert id="saveprimaryUBD" parameterType="com.founder.ec.entity.PrimaryUBD"> insert into user_behavior_data.primary_UBD ( sessionId, UUID, ip, memberId, firstPage, initTime, isNewVisit ) values ( #{sessionId}, #{uuid}, #{ip}, #{memberId}, #{firstPage}, #{initTime}, #{isNewVisit} ) </insert> <mapper> 项目结构如下: |
|
40分 |
看配置好像没有问题(还是眼拙没看出来),sqlmapping文件在类路径里了吧?
|
smct.insert("com.founder.ec.dao.impl.BehaviorDaoImpl.saveprimaryUBD",subd); |
|
请问,楼上类路径指的是什么路径
|
|
二楼方法走不通,我是单机跑的,不知道会不会有关系?
|
|
2楼已经给出答案了,把你ibatis的xml中的namespace加上
|
|
2楼方法,行不通,已经试过了。
|
|
问题解决了,与其说解决了问题,不如说避开了问题,转换一种思路,我把sqlMap.xml和ubd.xml中的mapper标签改为了sqlMap标签,这样问题就迎刃而解了。
最后,还是谢谢各位热心的回答! |