Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@198 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
6 changed files with 172 additions and 0 deletions
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
/* |
||||
* Copyright 2002-2006 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans.factory; |
||||
|
||||
import org.springframework.beans.TestBean; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class CountingFactory implements FactoryBean { |
||||
|
||||
private static int factoryBeanInstanceCount = 0; |
||||
|
||||
|
||||
/** |
||||
* Clear static state. |
||||
*/ |
||||
public static void reset() { |
||||
factoryBeanInstanceCount = 0; |
||||
} |
||||
|
||||
public static int getFactoryBeanInstanceCount() { |
||||
return factoryBeanInstanceCount; |
||||
} |
||||
|
||||
|
||||
public CountingFactory() { |
||||
factoryBeanInstanceCount++; |
||||
} |
||||
|
||||
public void setTestBean(TestBean tb) { |
||||
if (tb.getSpouse() == null) { |
||||
throw new IllegalStateException("TestBean needs to have spouse"); |
||||
} |
||||
} |
||||
|
||||
|
||||
public Object getObject() { |
||||
return "myString"; |
||||
} |
||||
|
||||
public Class getObjectType() { |
||||
return String.class; |
||||
} |
||||
|
||||
public boolean isSingleton() { |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> |
||||
|
||||
<beans> |
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" scope="prototype" autowire="constructor"/> |
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean" scope="prototype"/> |
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> |
||||
<property name="properties"> |
||||
<value>name=props1</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="false"> |
||||
<property name="properties"> |
||||
<value>name=props2</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> |
||||
|
||||
<beans> |
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" autowire="byType"/> |
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> |
||||
<property name="properties"> |
||||
<value>name=props1</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="false"> |
||||
<property name="properties"> |
||||
<value>name=props2</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory"> |
||||
<property name="testBean" ref="rob"/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" |
||||
default-autowire-candidates=""> |
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" autowire="byType"/> |
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean" autowire-candidate="true"/> |
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="true"> |
||||
<property name="properties"> |
||||
<value>name=props1</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> |
||||
<property name="properties"> |
||||
<value>name=props2</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory"> |
||||
<property name="testBean" ref="rob"/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" |
||||
default-autowire-candidates="props*,*ly"> |
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" autowire="byType"/> |
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean"/> |
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> |
||||
<property name="properties"> |
||||
<value>name=props1</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="false"> |
||||
<property name="properties"> |
||||
<value>name=props2</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="someProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> |
||||
<property name="properties"> |
||||
<value>name=someProps</value> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory"> |
||||
<property name="testBean" ref="rob"/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
Loading…
Reference in new issue