Spring will invoke specific constructor no matter this constructor is public or private
2016-12-04 21:47
513 查看
I have confirm this conclusion via debugging my own code.
Spring will invoke specific constructor no matter this constructor is public or private
This is my demo:
this is configuration file--applicationContext.xml
Program execute to this break point finally.
So, below conclusion is confirmed:
Spring will invoke specific constructor no matter this constructor is public or private
This program use Spring to initialize singleton creating bean. It also uses Factory pattern to instantiate object.
Demo code
// bean 'ZooKeeperManager' is registered as singleton bean in Spring Container after this line code.
ApplicationContext appContext = new ClassPathXmlApplicationContext("appContext.xml");
ZooKeeperManager manager = ZooKeeperManager.getInstance();
Spring will invoke specific constructor no matter this constructor is public or private
This is my demo:
package com.frank.zk; /** * * @author liushaomingdev@163.com * */ public class ZooKeeperManager extends ZookeeperClient implements Watcher { private static ZooKeeperManager INSTANCE; private ZooKeeperManager() { INSTANCE = this; } public static ZooKeeperManager getInstance() { return INSTANCE; } }
this is configuration file--applicationContext.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> <bean id="zookeeper" class="com.frank.zk.ZooKeeperManager" lazy-init="false" /> </beans>
Program execute to this break point finally.
private ZooKeeperManager() { INSTANCE = this; }
So, below conclusion is confirmed:
Spring will invoke specific constructor no matter this constructor is public or private
This program use Spring to initialize singleton creating bean. It also uses Factory pattern to instantiate object.
Demo code
// bean 'ZooKeeperManager' is registered as singleton bean in Spring Container after this line code.
ApplicationContext appContext = new ClassPathXmlApplicationContext("appContext.xml");
ZooKeeperManager manager = ZooKeeperManager.getInstance();
相关文章推荐
- 解闷ibatis与spring的配置( There is no statement named XXX in this SqlMap)
- HP-UX开机提示console is on a serial device,no further output will appear on this output device
- the breakpoint will not currently be hit. No executale code is currently loaded at this location
- This fragment should provide a default constructor (a public constructor with no arguments
- spring-boot 生成可执行jar报错:No compiler is provided in this environment
- no copy constructor available or copy constructor is declared 'explicit'
- SharePoint Designer Check In and Check Out Error – Cannot perform this operation.The file is no longer check out or has been del
- ibatis与spring的配置( There is no statement named XXX in this SqlMap)
- SharePoint Designer Can not perform this operation.The file is no longer checked out or has been del
- no copy constructor available or copy constructor is declared 'explicit'
- nagios报错Error: No such CGI app - /usr/local/nagios/sbin/nagios/cgi-bin/status.cgi may not exist or is not executable by this process.
- error C2558:no copy constructor available or copy constructor is declared 'explicit'
- Error: This class should provide a default constructor (a public constructor with no arguments)
- Overload resolution failed because no Public 'Add' is most specific for these arguments
- [INS-41107]eth0 selected for one or more of the public or private interfaces is not on a shared subn
- error C2558: class 'Driver' : no copy constructor available or copy constructor is declared 'explici
- About Derby "ERROR 42X51: The class '***' does not exist or is inaccessible. This can hap pen if the class is not public."
- spring No default constructor found; nested exception is java.lang.NoSuchMethodException: com.slj.mo
- Linux 3.9.10内核编译错误:multiple (or no) load addresses: This is incompatible with uImages的解决
- hpux (console is on a serial device,no further output will appear on this output device)