Spring factory-method 可以创建单例类
<bean id="config"
class="Configuration" factory-method="getInstance">
<!-- 配置文件路径 -->
<constructor-arg type="java.lang.String" value="config.properties"/>
</bean>
运用 factory-method创建单例 ,getInstance指定的是静态方法,而不是使用构造函数来创建类的实例
Configuration.java
private static Configuration _instance = null;
private Configuration(String configPath){
//执行你配置文件的加载
System.out.println("configPath");
}
public static Configuration getInstance(String configPath){
logger.info("init...");
if(_instance == null){
_instance = new Configuration(configPath);
}
return _instance;
}
分享到:
相关推荐
C#面向对象设计模式纵横谈(5):Factory Method 工厂方法模式(创建型模式) (Level 300)
对BeanFactory的相关所有接口的功能的关键点进行了总结描述,中文版本
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.core.Queue]: Factory method 'clientQueue' threw exception; nested exception is org....
实例工厂 <bean bean-factory="" factory-method=""> 管理对象 对象关系DI 构造器注入<construct-arg> set注入 生命周期 scope:prototype/singleton init-method destroy-method API ...
SpringIOC内部IOCSpring内部使用Spring 4.2.1-概念涵盖:: scopeconstructor-argpropertylookup-methodfactory-methodfactory-beaninit-methoddestroy-methodlazy-initabstractparentprimary
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面...<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath:proxool.properties ...
<bean id="mesDatasourcePropertiesFactory" class="com.ccc.db.impl.DatasourcePropertiesFactory" factory-method="getProperties"> <!-- userName--> <constructor-arg type="java.lang.String"> <value>...
·都需使用factory-method属性指定产生bean 实例的工厂方法。 ·工厂方法如果需要参数,都使用constructor-arg属性确定参数值。 ·其他依赖注入属性,都使用property 元素确定参数值。 Person.java ...
Instantiation with a static factory method .................................................... 30 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation iii Instantiation using an ...
<bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <value>classpath:jdbc.properties <!-- 配置數據源 --> destroy-method="close"> ${jdbc.driver}...
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath*:jdbc.properties <!-- 数据源配置,主要用于开发测试...
<bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <value>classpath:properties/jdbc.properties <!-- 配置數據源 --> destroy-method="close"> ${...
Instantiation with a static factory method .................................................... 30 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation iii Instantiation using an ...
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController' defined in ServletContext resource [/WEB-INF/springMVC-servlet.xml]: Error ...
spring框架中bean标签parent属性的各类使用范例 总计12个范例,涵盖了class、init-method、 factory-method、lazy-init、 depends-on、autowire 多种属性的组合使用
<bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <value>classpath:jdbc.properties <!-- 配置數據源 --> destroy-method="close"> ${jdbc.driver}...
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.ResourceMappings]: Factory method 'resourceMappings' threw exception; nested ...
6.4.1 <global-method-security>元素 65 使用protect-pointcut添加安全性切入点 66 6.5默认AccessDecisionManager 67 6.5.1自定义AccessDecisionManager 67 6.6验证管理器和命名空间 67 7.示例应用程序 69 7.1教程...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionInterceptor#0': Error setting property values; nested ...