In general, we register a bean in spring and directly
<id= "WebSocket" class= " Com.sdyy.common.spring.websocket.WebsocketEndPoint "/>
This creates an object bean for us, using the Websocketendpoint construction method (which is no parameter).
———————————————————————————— Dividing line —————————————————————————————————————————————
But there is another way to register beans with the Bean factory, there are three kinds of writing, we first look at the first kind:
The first method of writing and example parsing:
Take the famous Ehcahce, which is written in spring by the way it is registered in spring:
<id= "Realcache" class= " Org.springframework.cache.ehcache.EhCacheManagerFactoryBean "> < name = "Configlocation" value = "Classpath:cache/ehcache.xml" /> </ Bean >
But in the end you will find that the last bean generated is a net.sf.ehcache. The object of the CacheManager class, not the Org.springframework.cache.ehcache. Ehcachemanagerfactorybean
This is because the Ehcachemanagerfactorybean implements the spring Factorybean interface
Factorybean has three methods that require the implementation of
where The result returned by the GetObject method is returned to spring as a true registered result Bean, let's take a lookat
Org.springframework.cache.ehcache. What is returned by the Ehcachemanagerfactorybean GetObject method:
Yes, that's Net.sf.ehcache.CacheManager.
The second to third type of notation:
Through the factory bean can also write:
syntax:
< bean id =" Factorybean " class = "Com.demo.BaseBeanFactory" ></ bean > < bean id = "Bean" Factory-bean = "Factorybean" Factory-method = "Createbasedao" ></ bean >
Syntax two:
<bean id= "Bean" class= "com.demo.BaseBeanFactory" factory-method= "Createbasedao" ></bean>
Factory-method refers to which method is used to create the bean, and there is no requirement to inherit Factorybean.
Complete!
The Bean factory method registered with spring bean