Spring: Using builder pattern to create a bean

后端 未结 5 608
[愿得一人]
[愿得一人] 2020-12-08 00:54

I use ektorp to connect to CouchDB.

The way to build an ektorp HttpClient instance is to use builder pattern:

HttpClient httpClient = n         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-08 01:06

    While FactoryBean is cleaner there is a more quick-n-dirty method, using SpEL.

    This is how I've just configured the Neo4j driver:

    
        
        
            
                
                
            
        
        
    
    

    As you can see from the factory method's 3rd parameter, you can invoke a builder and its methods as a SpEL expression, with the nuance that classes have to be specified via their FQN. But that avoids you to write an entire boilerplate FactoryBean.

提交回复
热议问题