`
wenjinglian
  • 浏览: 807512 次
  • 性别: Icon_minigender_1
  • 来自: 株洲->深圳
社区版块
存档分类
最新评论

Spring: factory-method 如何传递参数

阅读更多

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;
}
分享到:
评论
1 楼 liff666 2011-03-14  
你的上面的代码 应该 可以 正常 执行的. 给你两个 链接 可以 作为参考
https://jira.springsource.org/browse/IDE-122?page=com.atlassian.jira.plugin.system.issuetabpanels%3Achangehistory-tabpanel

http://forum.springsource.org/showthread.php?t=56526

相关推荐

    C#面向对象设计模式纵横谈(5):Factory Method 工厂方法模式(创建型模式) (Level 300)

    C#面向对象设计模式纵横谈(5):Factory Method 工厂方法模式(创建型模式) (Level 300)

    Spring的BeanFactory的接口注解

    对BeanFactory的相关所有接口的功能的关键点进行了总结描述,中文版本

    spring-amqp-java-8:在 Java 8 上运行的示例项目

    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.core.Queue]: Factory method 'clientQueue' threw exception; nested exception is org....

    Spring.html

    实例工厂 &lt;bean bean-factory="" factory-method=""&gt; 管理对象 对象关系DI 构造器注入&lt;construct-arg&gt; set注入 生命周期 scope:prototype/singleton init-method destroy-method API ...

    SpringIOCInternals:IOCSpring内部

    SpringIOC内部IOCSpring内部使用Spring 4.2.1-概念涵盖:: scopeconstructor-argpropertylookup-methodfactory-methodfactory-beaninit-methoddestroy-methodlazy-initabstractparentprimary

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面...&lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;value&gt;classpath:proxool.properties ...

    spring applicationContext 配置文件

    &lt;bean id="mesDatasourcePropertiesFactory" class="com.ccc.db.impl.DatasourcePropertiesFactory" factory-method="getProperties"&gt; &lt;!-- userName--&gt; &lt;constructor-arg type="java.lang.String"&gt; &lt;value&gt;...

    spring 实例的工厂方法 依赖注入属性,都使用property 元素确

    ·都需使用factory-method属性指定产生bean 实例的工厂方法。 ·工厂方法如果需要参数,都使用constructor-arg属性确定参数值。 ·其他依赖注入属性,都使用property 元素确定参数值。 Person.java ...

    spring-framework-reference-4.1.2

    Instantiation with a static factory method .................................................... 30 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation iii Instantiation using an ...

    springmvc-ibatis

    &lt;bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"&gt; &lt;value&gt;classpath:jdbc.properties &lt;!-- 配置數據源 --&gt; destroy-method="close"&gt; ${jdbc.driver}...

    spring3.2+strut2+hibernate4

    &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;value&gt;classpath*:jdbc.properties &lt;!-- 数据源配置,主要用于开发测试...

    SpringMVC+Hibernate全注解整合

    &lt;bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"&gt; &lt;value&gt;classpath:properties/jdbc.properties &lt;!-- 配置數據源 --&gt; destroy-method="close"&gt; ${...

    spring-framework-reference4.1.4

    Instantiation with a static factory method .................................................... 30 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation iii Instantiation using an ...

    org.springframework.web.servlet-3.0.1.RELEASE-A.jar

    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 的parent属性示例

    spring框架中bean标签parent属性的各类使用范例 总计12个范例,涵盖了class、init-method、 factory-method、lazy-init、 depends-on、autowire 多种属性的组合使用

    SpringMVC-SSH全注解

    &lt;bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"&gt; &lt;value&gt;classpath:jdbc.properties &lt;!-- 配置數據源 --&gt; destroy-method="close"&gt; ${jdbc.driver}...

    spring-data-gosling-ldap

    org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.ResourceMappings]: Factory method 'resourceMappings' threw exception; nested ...

    spring security 参考手册中文版

    6.4.1 &lt;global-method-security&gt;元素 65 使用protect-pointcut添加安全性切入点 66 6.5默认AccessDecisionManager 67 6.5.1自定义AccessDecisionManager 67 6.6验证管理器和命名空间 67 7.示例应用程序 69 7.1教程...

    org.springframework.transaction-3.1.2.RELEASE.zip

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionInterceptor#0': Error setting property values; nested ...

Global site tag (gtag.js) - Google Analytics