标记在 方法上的时候,它会根据类型去spring容器中寻找 对于的形参并且注入。

 @Repository(value="userDao")
public class UserDaoImpl extends SqlSessionDaoSupport implements IUserDao{ // @Autowired
// @Qualifier(value="sqlsessionFactory11")
// private SqlSessionFactory asqlSessionFactory;
//
public User getOne(String uid) {
return this.getSqlSession().selectOne("cn.us.mybatis.getOne",uid);
} public List<User> getAllUsers() {
Object obj=this.getSqlSession();
return this.getSqlSession().selectList("cn.us.mybatis.getAllUsers");
} }

子类也可以,如果配置多个就会报错。

SqlSessionDaoSupport 中有以下方法
   @Autowired(required = false)
public final void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
if (!this.externalSqlSession) {
this.sqlSession = new SqlSessionTemplate(sqlSessionFactory);
}
}

只能一个bean,根据 type 类型去匹配的

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

因为 required=false,如果spring找不到的话会赋空值进去

如果没有@Autowired(required = false)的话,那么UserDaoImpl 不能继承

SqlSessionDaoSupport 了,可以用组合的方式 

然后
@Autowired
private SqlSessionFactory sqlSessionFactory;

然后在spring配置文件中,<bean id=...>配置上 SqlSessionFactory

@Autowired(required = false)的更多相关文章

  1. (转)@Autowired(required=false)注入注意的问题

    1.前言 在使用spring开发过程中,我们基本上都是使用@Autowired这个注解,用来注入已有的bean.但是有些时候,会注入失败.当我们加上参数(required=false)就能解决.今天整 ...

  2. [Spring]@Autowired,@Required,@Qualifier注解

    @Required注解 @Required注解用于setter方法,表明这个属性是必要的,不可少的,必须注入值 假设有个测试类,里面有name和password两个属性 我给两个属性的setter方法 ...

  3. org.springframework.beans.factory.annotation.Autowired(required=true)

    Injection of autowired dependencies failed ERROR org.springframework.web.context.ContextLoader  - Co ...

  4. Autowired(required=true)

    问题原因 没有实现类的接口上添加了@Autowired注解 问题解决 删掉@Autowired注解 bug详情 Description: Field userDAO in com.crab.servi ...

  5. String MVC @RequestParam(required=false) int XXX 参数为空报错解决方法

    今天在用@RequestParam(required=false) int XXX 取参数的时候,当参数没有的时候Spring默认赋值为空.而此时使用基本类型int,所以报错,建议使用包装类 Inte ...

  6. springtest mapper注入失败问题解决 {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    花费了一下午都没有搜索到相关解决方案的原因,一是我使用的 UnsatisfiedDependencyException 这个比较上层的异常(在最前面)来进行搜索, 范围太广导致没有搜索到,而且即便是有 ...

  7. @PathVariable设置为空的问题(required=false)

    参考了:http://www.imooc.com/qadetail/268268 最近学习springMVC的时候,学到@PathVariable后,发现@PathVariable有个required ...

  8. beans.factory.BeanCreationException beans.factory.annotation.Autowired(required=true)

    主要是这三个方面排查: 1,注入写成这样 @Autowired   private BrandServiceImpl      brandServiceImpl; 2,jar冲突,在pom.xml中 ...

  9. mvc5 @RenderSection("scripts", required: false) 什么意思

    在模板中 相当于占位符 使用方法如下 @section scripts{ //coding }

随机推荐

  1. JAVA nio 2 和 Path 类简介

    想要初步了解 NIO.2 API,也就是通常所说的“JSR203: More New I/O APIs for the Java Platform”,最好的切入点就是新的抽象类 java.nio.fi ...

  2. MySQL面试题集锦

    1. 如何设计一个高并发的系统 ① 数据库的优化,包括合理的事务隔离级别.SQL语句优化.索引的优化 ② 使用缓存,尽量减少数据库 IO ③ 分布式数据库.分布式缓存 ④ 服务器的负载均衡 2. 锁的 ...

  3. [runtime] MAObjCRuntime

    MAObjCRuntime 源码地址:(引入头文件MARTNSObject.h即可,非arc环境下) http://pan.baidu.com/s/1eQ6776U https://github.co ...

  4. 《Windows核心编程》第五章——作业

    #include <windows.h> #include<iostream> #include <tchar.h> using namespace std; ty ...

  5. Android图片加载框架最全解析(五),Glide强大的图片变换功能

    大家好,又到了学习Glide的时间了.前段时间由于项目开发紧张,再加上后来又生病了,所以停更了一个月,不过现在终于又可以恢复正常更新了.今天是这个系列的第五篇文章,在前面四篇文章的当中,我们已经学习了 ...

  6. eclipse无法启动

    -startupplugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar-showsplashorg.eclipse.platfo ...

  7. 依赖注入 DI 控制反转 IOC MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. AT&amp;T汇编语言——简单实例及工具演示

    今天就来用详细实例代码来运用一下昨天所说的仅仅个工具的使用方法吧 这几个实例基本的目的是来熟悉一下汇编相关工具的使用方法及应用一下昨天刚说的汇编程序模板. 我们用到的工具主要有as,ld,gcc,gd ...

  9. FM遇到错误RQP-DEF-0354和QE-DEF-0144

    版本:Cognos 10.2.1 系统:Win10 操作过程:在FM调用了一个存储过程,其中引用了前端page页面的参数如下图所示,在验证和保存查询主题的时候一直提示参数没有替换值,错误 信息如下图所 ...

  10. PCL学习笔记二:Registration (ICP算法)

    原文:http://blog.csdn.net/u010696366/article/details/8941938 PCL Registration API Registration:不断调整,把不 ...