`
boogie
  • 浏览: 234807 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

Configure a bean with factory using Spring DSL

阅读更多

1、How do I configure a bean like this using Spring DSL ?

    <bean id="mailSession" class="javax.mail.Session" factory-method="getInstance">
        <constructor-arg>
            <props>
                <prop key="mail.smtp.auth">true</prop>
            </props>
        </constructor-arg>
        <constructor-arg ref="smtpAuthenticator" />
    </bean>

 2、 To answer my own question it should look like this:

beans = {
  def props = new Properties()
  props.setProperty('mail.smtp.auth', 'true')

  mailSession(javax.mail.Session, props, ref('smtpAuthenticator')) { bean ->
     bean.factoryMethod = 'getInstance'
  }
  ...
}

   Note that using Properties makes the code less tidy than if the   property accepted a Map.

分享到:
评论

相关推荐

    Beginning Spring Boot 2 Applications and Microservices with the Spring Framework

    Siva Prasad Reddy Spring is the most popular Java-based framework for building enterprise ...applications quickly and easily, and the inner workings of Spring Boot using easy-to-follow examples.

    spring-boot-reference.pdf

    4. Working with Spring Boot 5. Learning about Spring Boot Features 6. Moving to Production 7. Advanced Topics II. Getting Started 8. Introducing Spring Boot 9. System Requirements 9.1. Servlet ...

    Spring源码学习五:BeanDefinition装载1

    // Configure the bean definition reader with this context's resource loading environment. beanDefinitionReader.setEnvironment(this.getEnvironment()); beanDefinitionReader.setResourceLoader(this); ...

    Spring和Mybatis整合英文文档翻译.pdf

    The SqlSessionFactoryBean provided by MyBatis-Spring simplifies the process of setting up the factory, allowing us to easily configure it with a DataSource. 2. **DataSource**: A DataSource is ...

    Spring Boot如何动态创建Bean示例代码

    Spring Boot动态创建Bean示例代码详解 Spring Boot框架中提供了多种方式来创建Bean,今天我们就来学习其中的一种,即动态创建Bean。动态创建Bean可以根据特定的条件来决定是否创建Bean,这在实际开发中非常有用。 ...

    Beginning-Spring-Boot-2.pdf

    Spring is the most popular Java-based framework for building enterprise applications....applications quickly and easily, and the inner workings of Spring Boot using easy-to-follow examples.

    Beginning Robotics with Raspberry Pi and Arduino_Using Python and OpenCV

    Beginning Robotics with Raspberry Pi and Arduino_Using Python and OpenCV-Apress(2018) Robotics does not have to be difficult. In this book, I introduce you to the field of robotics. The journey will ...

    How to configure DCM UDS with the DEXT Editor.pdf

    How to configure DCM UDS with the DEXT Editor.pdf

    Beginning Spring Boot 2

    As Spring is a very flexible and customizable framework, there are usually multiple ways to configure the application. Although it is a good thing to have multiple options, it can be overwhelming to ...

    Pro Spring Boot 2第2版-2009-EPUB版

    The author, a senior solutions architect and Principal Technical instructor with Pivotal, the company behind the Spring Framework, shares his experience, insights and first-hand knowledge about how ...

    S4H_367 Using Configure Your Solution and SSCUIs.pdf

    s4/hana cloud Using Configure Your Solution and SSCUIs

    thymeleaf-extras-springsecurity-3.0-master.zip

    This module provides a new dialect called org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect or org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect (depending on the ...

    Spring.MVC.Cookbook.1784396419

    Spring MVC is a lightweight application framework that comes with a great configuration by default. Being part of the Spring Framework, it naturally extended and supported it with an amazing set of ...

    MyEclipse Spring 入门教程

    通过右键点击文件,选择"Open With" -&gt; "Spring Bean Editor",可以看到一个图形化的界面,可以直观地管理Bean和它们的属性。 接下来,我们引入Spring的MVC框架进行Web开发。在`web.xml`中配置DispatcherServlet,...

    Mastering Spring Cloud-Packt Publishing(2018)

    Mastering Spring Cloud_Build self-healing, microservices-based, distributed systems using Spring Cloud-Packt Publishing(2018) Developing, deploying, and operating cloud applications should be as easy...

    Eclipse spring基本配置步骤

    "的输出,这表明Spring成功地实例化并注入了Bean。 以上就是在Eclipse中进行Spring基本配置的详细步骤。这只是Spring框架的冰山一角,更深入的应用包括事务管理、AOP、数据访问等,都需要进一步学习和实践。对于...

    Spring4整合Jersey2.9

    4. **创建Jersey Application子类**:在`MyApplication`类中,你需要注册Spring的ContextResolver,以便Jersey能从Spring容器中查找bean: ```java public class MyApplication extends ResourceConfig { public ...

    Spring.MVC.Beginner's.Guide.2nd.Edition.2016.7.pdf

    The book progressively teaches you to configure the Spring development environment, architecture, controllers, libraries, and more before moving on to developing a full web application. It begins with...

Global site tag (gtag.js) - Google Analytics