`
haofenglemon
  • 浏览: 240638 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Spring BYName

    博客分类:
  • user
阅读更多
pring中autowire="byName" /"byType"
pring中autowire="byName" /"byType"

     如果userDAO设置了autowire="byName" ,假设ServiceImpl有一个属性名为userDAO,Spring就会在配置文件里查找有没有名字为userDAO的bean, 自动为ServiceImpl注入。
     如果bean有两个属性,一个想默认注入,一个想自定义,只要设定了autowire,然后显式的声明那个想自定义的,就可以达到要求。这就应了需求,在需要特别配置的时候就提供配置,否则给我一个默认注入。
    还可以在根部的<beans>节点写一句default-autovwrie="byName",可以让文件里的所有bean 都默认autowrie。不过有人认为开发期可以这样,但Production Server上不应该使用Autowire。但有人认为那些自定义一次的地方比如TranscationManager应该详细定义,而 Dao,Service这种大量重复定义的bean就可以这样做。

<bean id="fileUploadController" class="fileuploadfolder.FileUploadController" autowire="byName">
        <property name="methodNameResolver"><ref bean="parameterMethodNameResolver"/></property>
        <property name="showListObj" value="Listsucess"/>         
       
    </bean>

分享到:
评论

相关推荐

    spring中的自动装配实例byName、byType

    spring中的自动装配实例byName、byType,两种装配方式的实例。有需要学习的朋友可以看一下。

    spring示例代码好又全.rar

    内容如下: spring.rar [spring_aop1] [spring_aop2] [spring_aop3] [spring_aop4] [spring_autowire_byName] [spring_autowire_byType] [spring_beginning] [spring_hibernate_1] [spring_hibernate_2] ...

    spring-agent.jar

    For environments where class instrumentation is ...Note that the virtual machine has to be started with the Spring agent, by supplying the following JVM options: -javaagent:/path/to/spring-agent.jar

    Spring的学习笔记

    (一) byName 13 (二) byType 14 (三) 注意 14 九、 生命周期 15 (一) lazy-init/default-lazy-init 15 (二) init-method destroy-method 不要和prototype一起用(了解) 15 第六课:annotation方式Spring 16 一、 ...

    spring-boot-reference.pdf

    Connecting to Elasticsearch by Using Spring Data 30.6.3. Spring Data Elasticsearch Repositories 30.7. Cassandra 30.7.1. Connecting to Cassandra 30.7.2. Spring Data Cassandra Repositories 30.8. ...

    spring4框架系列 [ 4 ]

    spring4框架系列 [ 4 ] 基于xml注入包含setter、构造、命名空间、集合属性、byName、byType、SPEL、匿名Bean、同类抽象、异类抽象、配置多子配置文件

    spring自动装配例子

    (2)byName:根据属性 名 自动装配,设值注入 &lt;bean id="xxx" class="xxx" &gt;&lt;/bean&gt; (3)byType:根据属性 类型 自动装配,相同类型多个会抛出异常,设值注入 &lt;bean class="xxx" &gt;&lt;/bean&gt; (4)constructor:与 ...

    thymeleaf-extras-springsecurity-3.0-master.zip

    They work equivalently to a th:if that evaluated an #authorization.[removed]...) expression, by evaluating a Spring Security Expression: ('ROLE_ADMIN')"&gt; This will only be displayed if ...

    spring2.5 学习笔记

    (一) byName 13 (二) byType 14 (三) 注意 14 九、 生命周期 15 (一) lazy-init/default-lazy-init 15 (二) init-method destroy-method 不要和prototype一起用(了解) 15 第六课:annotation方式Spring 16 一、 ...

    org.springframework.web.servlet-3.1.0.RELEASE

    * view name which will need to be resolved by a ViewResolver object; * alternatively a View object can be specified directly. The model * is a Map, allowing the use of multiple objects keyed by ...

    spring-autowire-demo.zip

    以Spring5.3.6为演示基础,以多个范例显示演示了autowire多种形式的应用 default、byName、byType、constructor 并对相关使用做了一定的对比

    spring aop 实现源代码--xml and annotation(带lib包)

    Log before public abstract void com.savage.simplespring.bean.MessageSender.send(java.lang.String) by LogBeforeAdvice. Send Message[message] by http. 正如你所看到的,在执行MessageSender的send方法前先...

    spring-framework-reference-4.1.2

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    spring基础

    @Resource 的作用相当于 @Autowired,只不过 @Autowired 按 byType 自动注入,面 @Resource 默认按 byName 自动注入罢了。@Resource 有两个属性是比较重要的,分别是 name 和 type,Spring 将 @Resource 注释的 name...

    Spring的自动装配源代码

    spring中的自动装配的形式byType、byName、no、construtor、autodetect和default(beans标签中没有,而bean标签中有该属性)共6种装配的方式的举例说明

    Spring_1_IOC

    Spring_1_IOC, 1.简单的依赖注入。 2.对象的生命周期:单例/原型。 3.依赖注入的两种方式:设值注入/构造注入。 4.对象工厂的延迟创建。 5.自动装配:byName/byType。

    spring-learn:Spring轻松学习demo

    byName根据属性名称自动装配-set注入 byType在容器中查找指定属性类型进行装配-set注入 构造函数与byType类似-构造方法注入 5.豆的注解 @Autowired可以注解列表和地图; @Order(1)更改注解顺序,list中有效 @...

    pro spring dm server

    When it came to the final release, the name was changed to the SpringSource dm Server, and the SpringSource Application Platform’s scope was extended to include a set of SpringSource tools, ...

    springMVC-annotation注解介绍

    3、@Resource和@Autowired ...如果我们想使用按照名称(byName)来装配,可以结合@Qualifier注解一起使用。如下: public class TestServiceImpl { @Autowired @Qualifier("userDao") private UserDao userDao; }

    基于注解的DI.docx

    常用注解: @Component、创建对象 ...@Autowired、spring框架中引用类型赋值的注解,支持byName、byType,默认byType @Resource、jdk中的注解,使用自动注入给引用数据类型赋值,支持byName、byType,默认byName

Global site tag (gtag.js) - Google Analytics