service
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public int insertUser(User user) {
int result=userMapper.insert(user);
return result;
}
}
spring-dao
<context:component-scan base-package="com.zone.service"></context:component-scan>
<context:property-placeholder location="classpath:resource/*.properties"/>
<!-- 数据库连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="driverClassName" value="${jdbc.driver}" />
<property name="maxActive" value="10" />
<property name="minIdle" value="3" />
</bean>
<!-- spring管理sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 加载mybatis的全局配置文件 -->
<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property>
</bean>
<!-- 配置扫描包,加载mapper代理对象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.zone.mapper"></property>
</bean>
啊,我的也是这样,疯掉了
看下UserMapper ,增加注解@Service了吗?
如果是springboot项目,看下你的启动项mapper扫描范围
解决了没有,我的也是,求
同问,而且我的更奇怪,写在jar包里的 一个工程就可以正常跑起来,另一个就不能。。。。。。完全没有头绪
可能是mapper类 没有写@Mapper注解
spring的注解扫描开了没