qq_35352213 2016-12-15 09:02 采纳率: 0%
浏览 2715

ssm整合mapper注入失败

spring配置文件
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

<!-- 加载资源文件 -->
<context:property-placeholder location="classpath:db.properties" />

<!-- 开启注解扫描 -->
<context:component-scan base-package="com.spring"></context:component-scan>


<!-- 配置数据源,并设置数据源 -->
<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="user" value="${jdbc.username}"></property>
    <property name="password" value="${jdbc.password}"></property>
    <property name="jdbcUrl" value="${jdbc.url}"></property>
    <property name="driverClass" value="${jdbc.driver}"></property>
    <property name="maxPoolSize" value="500"></property>
</bean>

<!-- 配置sqlsessionfactory -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="c3p0DataSource"></property>
    <property name="configLocation" value="classpath:SqlMapConfig.xml"></property>
</bean>

<!-- 批量配置mybit的mapper接口,默认bean的id为类名首字母小写 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.spring.dao"></property>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean"></property>
</bean>


<!-- jdbc事务管理器 -->
<bean id="dataSourceTransactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="c3p0DataSource"></property>

</bean>

<!-- 事务通知 -->
<tx:advice id="txAdvice" transaction-manager="dataSourceTransactionManager">

    <tx:attributes>
        <tx:method name="*" isolation="DEFAULT" propagation="REQUIRED" />
    </tx:attributes>

</tx:advice>

<aop:config>
    <aop:advisor advice-ref="txAdvice"
        pointcut="execution(* com.spring.dao.*.*(..))" />
</aop:config>

springmvc配置

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

<!-- 开启注解扫描 -->
<context:component-scan base-package="com.spring"></context:component-scan>

<mvc:annotation-driven />



<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsps/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

<?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">

mybatis

<settings>
    <setting name="lazyLoadingEnabled" value="true" />
    <setting name="aggressiveLazyLoading" value="false" />
    <setting name="logImpl" value="LOG4J" />
</settings>

<mappers>
    <mapper resource="com/spring/dao/Student.xml" />
</mappers>

映射文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">



INSERT student
(student_name) VALUES(#{student_name})

<delete id="delete">
    delete from student where studentid=#{id}

</delete>

<select id="findstudentbyid" parameterType="int"
    resultType="com.spring.dao.Student">
    select * from student where studentid=#{id}
</select>

<select id="findAllstudent" resultType="com.spring.dao.Student">
    select * from student
</select>

<update id="update" parameterType="com.spring.dao.Student">
    update student set
    student_name=#{student_name} where
    studentid=#{studentid}
</update>

  • 写回答

1条回答

  • ExceptionMapping 2017-01-03 02:35
    关注

    按ctrl键点鼠标,路经都找得到么?

    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘