refactored XmlBeanFactoryTests in preparation for move from .testsuite -> .context
This commit is contained in:
parent
7a0d9c7533
commit
78c692b0cb
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.beans.IndexedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Simple bean used to check constructor dependency checking.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 09.11.2003
|
||||
*/
|
||||
public class ConstructorDependenciesBean implements Serializable {
|
||||
|
||||
private int age;
|
||||
|
||||
private String name;
|
||||
|
||||
private TestBean spouse1;
|
||||
|
||||
private TestBean spouse2;
|
||||
|
||||
private IndexedTestBean other;
|
||||
|
||||
public ConstructorDependenciesBean(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1) {
|
||||
this.spouse1 = spouse1;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, int age) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
this.other = other;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public TestBean getSpouse1() {
|
||||
return spouse1;
|
||||
}
|
||||
|
||||
public TestBean getSpouse2() {
|
||||
return spouse2;
|
||||
}
|
||||
|
||||
public IndexedTestBean getOther() {
|
||||
return other;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
import org.springframework.beans.ITestBean;
|
||||
|
||||
/**
|
||||
* Bean testing the ability to use both lookup method overrides
|
||||
* and constructor injection.
|
||||
* There is also a property ("setterString") to be set via
|
||||
* Setter Injection.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public abstract class ConstructorInjectedOverrides {
|
||||
|
||||
private ITestBean tb;
|
||||
|
||||
private String setterString;
|
||||
|
||||
public ConstructorInjectedOverrides(ITestBean tb) {
|
||||
this.tb = tb;
|
||||
}
|
||||
|
||||
public ITestBean getTestBean() {
|
||||
return this.tb;
|
||||
}
|
||||
|
||||
|
||||
protected abstract FactoryMethods createFactoryMethods();
|
||||
|
||||
/**
|
||||
* @return Returns the setterString.
|
||||
*/
|
||||
public String getSetterString() {
|
||||
return setterString;
|
||||
}
|
||||
/**
|
||||
* @param setterString The setterString to set.
|
||||
*/
|
||||
public void setSetterString(String setterString) {
|
||||
this.setterString = setterString;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,11 +22,15 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
|||
|
||||
/**
|
||||
* Simple bean used to test dependency checking.
|
||||
*
|
||||
* Note: would be defined within {@link XmlBeanFactoryTestTypes}, but must be a public type
|
||||
* in order to satisfy test dependencies.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
* @since 04.09.2003
|
||||
*/
|
||||
public class DependenciesBean implements BeanFactoryAware {
|
||||
public final class DependenciesBean implements BeanFactoryAware {
|
||||
|
||||
private int age;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
import org.springframework.beans.IndexedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Simple bean used to check constructor dependency checking.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 09.11.2003
|
||||
*/
|
||||
class DerivedConstructorDependenciesBean extends ConstructorDependenciesBean {
|
||||
|
||||
boolean initialized;
|
||||
boolean destroyed;
|
||||
|
||||
DerivedConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other) {
|
||||
super(spouse1, spouse2, other);
|
||||
}
|
||||
|
||||
private DerivedConstructorDependenciesBean(TestBean spouse1, Object spouse2, IndexedTestBean other) {
|
||||
super(spouse1, null, other);
|
||||
}
|
||||
|
||||
protected DerivedConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other, int age, int otherAge) {
|
||||
super(spouse1, spouse2, other);
|
||||
}
|
||||
|
||||
public DerivedConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other, int age, String name) {
|
||||
super(spouse1, spouse2, other);
|
||||
setAge(age);
|
||||
setName(name);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
private void destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public interface DummyBo {
|
||||
|
||||
void something();
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class DummyBoImpl implements DummyBo {
|
||||
|
||||
DummyDao dao;
|
||||
|
||||
public DummyBoImpl(DummyDao dao) {
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
public void something() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class DummyDao {
|
||||
|
||||
DataSource ds;
|
||||
|
||||
public DummyDao(DataSource ds) {
|
||||
this.ds = ds;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.DummyFactory;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 21.07.2003
|
||||
*/
|
||||
public class DummyReferencer {
|
||||
|
||||
private TestBean testBean1;
|
||||
|
||||
private TestBean testBean2;
|
||||
|
||||
private DummyFactory dummyFactory;
|
||||
|
||||
|
||||
public DummyReferencer() {
|
||||
}
|
||||
|
||||
public DummyReferencer(DummyFactory dummyFactory) {
|
||||
this.dummyFactory = dummyFactory;
|
||||
}
|
||||
|
||||
public void setDummyFactory(DummyFactory dummyFactory) {
|
||||
this.dummyFactory = dummyFactory;
|
||||
}
|
||||
|
||||
public DummyFactory getDummyFactory() {
|
||||
return dummyFactory;
|
||||
}
|
||||
|
||||
public void setTestBean1(TestBean testBean1) {
|
||||
this.testBean1 = testBean1;
|
||||
}
|
||||
|
||||
public TestBean getTestBean1() {
|
||||
return testBean1;
|
||||
}
|
||||
|
||||
public void setTestBean2(TestBean testBean2) {
|
||||
this.testBean2 = testBean2;
|
||||
}
|
||||
|
||||
public TestBean getTestBean2() {
|
||||
return testBean2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* 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.xml;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Test class for Spring's ability to create objects using static
|
||||
* factory methods, rather than constructors.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class FactoryMethods {
|
||||
|
||||
public static FactoryMethods nullInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FactoryMethods defaultInstance() {
|
||||
TestBean tb = new TestBean();
|
||||
tb.setName("defaultInstance");
|
||||
return new FactoryMethods(tb, "default", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that overloaded methods are supported.
|
||||
*/
|
||||
public static FactoryMethods newInstance(TestBean tb) {
|
||||
return new FactoryMethods(tb, "default", 0);
|
||||
}
|
||||
|
||||
protected static FactoryMethods newInstance(TestBean tb, int num, String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalStateException("Should never be called with null value");
|
||||
}
|
||||
return new FactoryMethods(tb, name, num);
|
||||
}
|
||||
|
||||
static FactoryMethods newInstance(TestBean tb, int num, Integer something) {
|
||||
if (something != null) {
|
||||
throw new IllegalStateException("Should never be called with non-null value");
|
||||
}
|
||||
return new FactoryMethods(tb, null, num);
|
||||
}
|
||||
|
||||
private static List listInstance() {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
private int num = 0;
|
||||
private String name = "default";
|
||||
private TestBean tb;
|
||||
private String stringValue;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor is private: not for use outside this class,
|
||||
* even by IoC container.
|
||||
*/
|
||||
private FactoryMethods(TestBean tb, String name, int num) {
|
||||
this.tb = tb;
|
||||
this.name = name;
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public void setStringValue(String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return this.stringValue;
|
||||
}
|
||||
|
||||
public TestBean getTestBean() {
|
||||
return this.tb;
|
||||
}
|
||||
|
||||
protected TestBean protectedGetTestBean() {
|
||||
return this.tb;
|
||||
}
|
||||
|
||||
private TestBean privateGetTestBean() {
|
||||
return this.tb;
|
||||
}
|
||||
|
||||
public int getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set via Setter Injection once instance is created.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.beans.factory.support.MethodReplacer;
|
||||
|
||||
/**
|
||||
* Fixed method replacer for String return types
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class FixedMethodReplacer implements MethodReplacer {
|
||||
|
||||
public static final String VALUE = "fixedMethodReplacer";
|
||||
|
||||
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable {
|
||||
return VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* 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.xml;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class MapAndSet {
|
||||
|
||||
private Object obj;
|
||||
|
||||
public MapAndSet(Map map) {
|
||||
this.obj = map;
|
||||
}
|
||||
|
||||
public MapAndSet(Set set) {
|
||||
this.obj = set;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class MethodReplaceCandidate {
|
||||
|
||||
public String replaceMe(String echo) {
|
||||
return echo;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* 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.xml;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Bean that exposes a simple property that can be set
|
||||
* to a mix of references and individual values.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @since 27.05.2003
|
||||
*/
|
||||
public class MixedCollectionBean {
|
||||
|
||||
private Collection jumble;
|
||||
|
||||
|
||||
public void setJumble(Collection jumble) {
|
||||
this.jumble = jumble;
|
||||
}
|
||||
|
||||
public Collection getJumble() {
|
||||
return jumble;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* 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.xml;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public interface OverrideInterface {
|
||||
|
||||
TestBean getPrototypeDependency();
|
||||
|
||||
TestBean getPrototypeDependency(Object someParam);
|
||||
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* 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.xml;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public abstract class OverrideOneMethod extends MethodReplaceCandidate implements OverrideInterface {
|
||||
|
||||
protected abstract TestBean protectedOverrideSingleton();
|
||||
|
||||
public TestBean getPrototypeDependency(Object someParam) {
|
||||
return new TestBean();
|
||||
}
|
||||
|
||||
public TestBean invokesOverridenMethodOnSelf() {
|
||||
return getPrototypeDependency();
|
||||
}
|
||||
|
||||
public String echo(String echo) {
|
||||
return echo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded form of replaceMe.
|
||||
*/
|
||||
public String replaceMe() {
|
||||
return "replaceMe";
|
||||
}
|
||||
|
||||
/**
|
||||
* Another overloaded form of replaceMe, not getting replaced.
|
||||
* Must not cause errors when the other replaceMe methods get replaced.
|
||||
*/
|
||||
public String replaceMe(int someParam) {
|
||||
return "replaceMe:" + someParam;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
/**
|
||||
* Subclass of OverrideOneMethod, to check that overriding is
|
||||
* supported for inherited methods.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public abstract class OverrideOneMethodSubclass extends OverrideOneMethod {
|
||||
|
||||
protected void doSomething(String arg) {
|
||||
// This implementation does nothing!
|
||||
// It's not overloaded
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2007 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.xml;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
|
||||
/**
|
||||
* Simple test of BeanFactory initialization and lifecycle callbacks.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class ProtectedLifecycleBean implements BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {
|
||||
|
||||
protected boolean initMethodDeclared = false;
|
||||
|
||||
protected String beanName;
|
||||
|
||||
protected BeanFactory owningFactory;
|
||||
|
||||
protected boolean postProcessedBeforeInit;
|
||||
|
||||
protected boolean inited;
|
||||
|
||||
protected boolean initedViaDeclaredInitMethod;
|
||||
|
||||
protected boolean postProcessedAfterInit;
|
||||
|
||||
protected boolean destroyed;
|
||||
|
||||
|
||||
public void setInitMethodDeclared(boolean initMethodDeclared) {
|
||||
this.initMethodDeclared = initMethodDeclared;
|
||||
}
|
||||
|
||||
public boolean isInitMethodDeclared() {
|
||||
return initMethodDeclared;
|
||||
}
|
||||
|
||||
public void setBeanName(String name) {
|
||||
this.beanName = name;
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.owningFactory = beanFactory;
|
||||
}
|
||||
|
||||
public void postProcessBeforeInit() {
|
||||
if (this.inited || this.initedViaDeclaredInitMethod) {
|
||||
throw new RuntimeException("Factory called postProcessBeforeInit after afterPropertiesSet");
|
||||
}
|
||||
if (this.postProcessedBeforeInit) {
|
||||
throw new RuntimeException("Factory called postProcessBeforeInit twice");
|
||||
}
|
||||
this.postProcessedBeforeInit = true;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
if (this.owningFactory == null) {
|
||||
throw new RuntimeException("Factory didn't call setBeanFactory before afterPropertiesSet on lifecycle bean");
|
||||
}
|
||||
if (!this.postProcessedBeforeInit) {
|
||||
throw new RuntimeException("Factory didn't call postProcessBeforeInit before afterPropertiesSet on lifecycle bean");
|
||||
}
|
||||
if (this.initedViaDeclaredInitMethod) {
|
||||
throw new RuntimeException("Factory initialized via declared init method before initializing via afterPropertiesSet");
|
||||
}
|
||||
if (this.inited) {
|
||||
throw new RuntimeException("Factory called afterPropertiesSet twice");
|
||||
}
|
||||
this.inited = true;
|
||||
}
|
||||
|
||||
public void declaredInitMethod() {
|
||||
if (!this.inited) {
|
||||
throw new RuntimeException("Factory didn't call afterPropertiesSet before declared init method");
|
||||
}
|
||||
|
||||
if (this.initedViaDeclaredInitMethod) {
|
||||
throw new RuntimeException("Factory called declared init method twice");
|
||||
}
|
||||
this.initedViaDeclaredInitMethod = true;
|
||||
}
|
||||
|
||||
public void postProcessAfterInit() {
|
||||
if (!this.inited) {
|
||||
throw new RuntimeException("Factory called postProcessAfterInit before afterPropertiesSet");
|
||||
}
|
||||
if (this.initMethodDeclared && !this.initedViaDeclaredInitMethod) {
|
||||
throw new RuntimeException("Factory called postProcessAfterInit before calling declared init method");
|
||||
}
|
||||
if (this.postProcessedAfterInit) {
|
||||
throw new RuntimeException("Factory called postProcessAfterInit twice");
|
||||
}
|
||||
this.postProcessedAfterInit = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy business method that will fail unless the factory
|
||||
* managed the bean's lifecycle correctly
|
||||
*/
|
||||
public void businessMethod() {
|
||||
if (!this.inited || (this.initMethodDeclared && !this.initedViaDeclaredInitMethod) ||
|
||||
!this.postProcessedAfterInit) {
|
||||
throw new RuntimeException("Factory didn't initialize lifecycle object correctly");
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (this.destroyed) {
|
||||
throw new IllegalStateException("Already destroyed");
|
||||
}
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
||||
public boolean isDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
|
||||
public static class PostProcessor implements BeanPostProcessor {
|
||||
|
||||
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
|
||||
if (bean instanceof ProtectedLifecycleBean) {
|
||||
((ProtectedLifecycleBean) bean).postProcessBeforeInit();
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
|
||||
if (bean instanceof ProtectedLifecycleBean) {
|
||||
((ProtectedLifecycleBean) bean).postProcessAfterInit();
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* The Spring Framework is published under the terms
|
||||
* of the Apache Software License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.beans.factory.support.MethodReplacer;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class ReverseMethodReplacer implements MethodReplacer, Serializable {
|
||||
|
||||
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable {
|
||||
String s = (String) args[0];
|
||||
return new StringBuffer(s).reverse().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public abstract class SerializableMethodReplacerCandidate extends MethodReplaceCandidate implements Serializable {
|
||||
|
||||
//public abstract Point getPoint();
|
||||
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2005 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.xml;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 23.10.2004
|
||||
*/
|
||||
public class SingleSimpleTypeConstructorBean {
|
||||
|
||||
private boolean singleBoolean;
|
||||
|
||||
private boolean secondBoolean;
|
||||
|
||||
private String testString;
|
||||
|
||||
public SingleSimpleTypeConstructorBean(boolean singleBoolean) {
|
||||
this.singleBoolean = singleBoolean;
|
||||
}
|
||||
|
||||
public SingleSimpleTypeConstructorBean(String testString, boolean secondBoolean) {
|
||||
this.testString = testString;
|
||||
this.secondBoolean = secondBoolean;
|
||||
}
|
||||
|
||||
public boolean isSingleBoolean() {
|
||||
return singleBoolean;
|
||||
}
|
||||
|
||||
public boolean isSecondBoolean() {
|
||||
return secondBoolean;
|
||||
}
|
||||
|
||||
public String getTestString() {
|
||||
return testString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,732 @@
|
|||
/*
|
||||
* Copyright 2002-2008 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.xml;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.IndexedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.DummyFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.support.MethodReplacer;
|
||||
|
||||
|
||||
/**
|
||||
* Types used by {@link XmlBeanFactoryTests} and its attendant XML config files.
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
final class XmlBeanFactoryTestTypes { }
|
||||
|
||||
/**
|
||||
* Simple bean used to check constructor dependency checking.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 09.11.2003
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class ConstructorDependenciesBean implements Serializable {
|
||||
|
||||
private int age;
|
||||
|
||||
private String name;
|
||||
|
||||
private TestBean spouse1;
|
||||
|
||||
private TestBean spouse2;
|
||||
|
||||
private IndexedTestBean other;
|
||||
|
||||
public ConstructorDependenciesBean(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1) {
|
||||
this.spouse1 = spouse1;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, int age) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
this.other = other;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public TestBean getSpouse1() {
|
||||
return spouse1;
|
||||
}
|
||||
|
||||
public TestBean getSpouse2() {
|
||||
return spouse2;
|
||||
}
|
||||
|
||||
public IndexedTestBean getOther() {
|
||||
return other;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bean testing the ability to use both lookup method overrides
|
||||
* and constructor injection.
|
||||
* There is also a property ("setterString") to be set via
|
||||
* Setter Injection.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
abstract class ConstructorInjectedOverrides {
|
||||
|
||||
private ITestBean tb;
|
||||
|
||||
private String setterString;
|
||||
|
||||
public ConstructorInjectedOverrides(ITestBean tb) {
|
||||
this.tb = tb;
|
||||
}
|
||||
|
||||
public ITestBean getTestBean() {
|
||||
return this.tb;
|
||||
}
|
||||
|
||||
|
||||
protected abstract FactoryMethods createFactoryMethods();
|
||||
|
||||
/**
|
||||
* @return Returns the setterString.
|
||||
*/
|
||||
public String getSetterString() {
|
||||
return setterString;
|
||||
}
|
||||
/**
|
||||
* @param setterString The setterString to set.
|
||||
*/
|
||||
public void setSetterString(String setterString) {
|
||||
this.setterString = setterString;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple bean used to check constructor dependency checking.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 09.11.2003
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class DerivedConstructorDependenciesBean extends ConstructorDependenciesBean {
|
||||
|
||||
boolean initialized;
|
||||
boolean destroyed;
|
||||
|
||||
DerivedConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other) {
|
||||
super(spouse1, spouse2, other);
|
||||
}
|
||||
|
||||
private DerivedConstructorDependenciesBean(TestBean spouse1, Object spouse2, IndexedTestBean other) {
|
||||
super(spouse1, null, other);
|
||||
}
|
||||
|
||||
protected DerivedConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other, int age, int otherAge) {
|
||||
super(spouse1, spouse2, other);
|
||||
}
|
||||
|
||||
public DerivedConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other, int age, String name) {
|
||||
super(spouse1, spouse2, other);
|
||||
setAge(age);
|
||||
setName(name);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
private void destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
interface DummyBo {
|
||||
|
||||
void something();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
class DummyBoImpl implements DummyBo {
|
||||
|
||||
DummyDao dao;
|
||||
|
||||
public DummyBoImpl(DummyDao dao) {
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
public void something() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
class DummyDao {
|
||||
|
||||
DataSource ds;
|
||||
|
||||
public DummyDao(DataSource ds) {
|
||||
this.ds = ds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 21.07.2003
|
||||
*/
|
||||
class DummyReferencer {
|
||||
|
||||
private TestBean testBean1;
|
||||
|
||||
private TestBean testBean2;
|
||||
|
||||
private DummyFactory dummyFactory;
|
||||
|
||||
|
||||
public DummyReferencer() {
|
||||
}
|
||||
|
||||
public DummyReferencer(DummyFactory dummyFactory) {
|
||||
this.dummyFactory = dummyFactory;
|
||||
}
|
||||
|
||||
public void setDummyFactory(DummyFactory dummyFactory) {
|
||||
this.dummyFactory = dummyFactory;
|
||||
}
|
||||
|
||||
public DummyFactory getDummyFactory() {
|
||||
return dummyFactory;
|
||||
}
|
||||
|
||||
public void setTestBean1(TestBean testBean1) {
|
||||
this.testBean1 = testBean1;
|
||||
}
|
||||
|
||||
public TestBean getTestBean1() {
|
||||
return testBean1;
|
||||
}
|
||||
|
||||
public void setTestBean2(TestBean testBean2) {
|
||||
this.testBean2 = testBean2;
|
||||
}
|
||||
|
||||
public TestBean getTestBean2() {
|
||||
return testBean2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test class for Spring's ability to create objects using static
|
||||
* factory methods, rather than constructors.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class FactoryMethods {
|
||||
|
||||
public static FactoryMethods nullInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FactoryMethods defaultInstance() {
|
||||
TestBean tb = new TestBean();
|
||||
tb.setName("defaultInstance");
|
||||
return new FactoryMethods(tb, "default", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that overloaded methods are supported.
|
||||
*/
|
||||
public static FactoryMethods newInstance(TestBean tb) {
|
||||
return new FactoryMethods(tb, "default", 0);
|
||||
}
|
||||
|
||||
protected static FactoryMethods newInstance(TestBean tb, int num, String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalStateException("Should never be called with null value");
|
||||
}
|
||||
return new FactoryMethods(tb, name, num);
|
||||
}
|
||||
|
||||
static FactoryMethods newInstance(TestBean tb, int num, Integer something) {
|
||||
if (something != null) {
|
||||
throw new IllegalStateException("Should never be called with non-null value");
|
||||
}
|
||||
return new FactoryMethods(tb, null, num);
|
||||
}
|
||||
|
||||
private static List<?> listInstance() {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
private int num = 0;
|
||||
private String name = "default";
|
||||
private TestBean tb;
|
||||
private String stringValue;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor is private: not for use outside this class,
|
||||
* even by IoC container.
|
||||
*/
|
||||
private FactoryMethods(TestBean tb, String name, int num) {
|
||||
this.tb = tb;
|
||||
this.name = name;
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public void setStringValue(String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return this.stringValue;
|
||||
}
|
||||
|
||||
public TestBean getTestBean() {
|
||||
return this.tb;
|
||||
}
|
||||
|
||||
protected TestBean protectedGetTestBean() {
|
||||
return this.tb;
|
||||
}
|
||||
|
||||
private TestBean privateGetTestBean() {
|
||||
return this.tb;
|
||||
}
|
||||
|
||||
public int getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set via Setter Injection once instance is created.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed method replacer for String return types
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
class FixedMethodReplacer implements MethodReplacer {
|
||||
|
||||
public static final String VALUE = "fixedMethodReplacer";
|
||||
|
||||
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable {
|
||||
return VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class MapAndSet {
|
||||
|
||||
private Object obj;
|
||||
|
||||
public MapAndSet(Map<?, ?> map) {
|
||||
this.obj = map;
|
||||
}
|
||||
|
||||
public MapAndSet(Set<?> set) {
|
||||
this.obj = set;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
class MethodReplaceCandidate {
|
||||
|
||||
public String replaceMe(String echo) {
|
||||
return echo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bean that exposes a simple property that can be set
|
||||
* to a mix of references and individual values.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @since 27.05.2003
|
||||
*/
|
||||
class MixedCollectionBean {
|
||||
|
||||
private Collection<?> jumble;
|
||||
|
||||
|
||||
public void setJumble(Collection<?> jumble) {
|
||||
this.jumble = jumble;
|
||||
}
|
||||
|
||||
public Collection<?> getJumble() {
|
||||
return jumble;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
interface OverrideInterface {
|
||||
|
||||
TestBean getPrototypeDependency();
|
||||
|
||||
TestBean getPrototypeDependency(Object someParam);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
abstract class OverrideOneMethod extends MethodReplaceCandidate implements OverrideInterface {
|
||||
|
||||
protected abstract TestBean protectedOverrideSingleton();
|
||||
|
||||
public TestBean getPrototypeDependency(Object someParam) {
|
||||
return new TestBean();
|
||||
}
|
||||
|
||||
public TestBean invokesOverridenMethodOnSelf() {
|
||||
return getPrototypeDependency();
|
||||
}
|
||||
|
||||
public String echo(String echo) {
|
||||
return echo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded form of replaceMe.
|
||||
*/
|
||||
public String replaceMe() {
|
||||
return "replaceMe";
|
||||
}
|
||||
|
||||
/**
|
||||
* Another overloaded form of replaceMe, not getting replaced.
|
||||
* Must not cause errors when the other replaceMe methods get replaced.
|
||||
*/
|
||||
public String replaceMe(int someParam) {
|
||||
return "replaceMe:" + someParam;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclass of OverrideOneMethod, to check that overriding is
|
||||
* supported for inherited methods.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
abstract class OverrideOneMethodSubclass extends OverrideOneMethod {
|
||||
|
||||
protected void doSomething(String arg) {
|
||||
// This implementation does nothing!
|
||||
// It's not overloaded
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple test of BeanFactory initialization and lifecycle callbacks.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class ProtectedLifecycleBean implements BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {
|
||||
|
||||
protected boolean initMethodDeclared = false;
|
||||
|
||||
protected String beanName;
|
||||
|
||||
protected BeanFactory owningFactory;
|
||||
|
||||
protected boolean postProcessedBeforeInit;
|
||||
|
||||
protected boolean inited;
|
||||
|
||||
protected boolean initedViaDeclaredInitMethod;
|
||||
|
||||
protected boolean postProcessedAfterInit;
|
||||
|
||||
protected boolean destroyed;
|
||||
|
||||
|
||||
public void setInitMethodDeclared(boolean initMethodDeclared) {
|
||||
this.initMethodDeclared = initMethodDeclared;
|
||||
}
|
||||
|
||||
public boolean isInitMethodDeclared() {
|
||||
return initMethodDeclared;
|
||||
}
|
||||
|
||||
public void setBeanName(String name) {
|
||||
this.beanName = name;
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.owningFactory = beanFactory;
|
||||
}
|
||||
|
||||
public void postProcessBeforeInit() {
|
||||
if (this.inited || this.initedViaDeclaredInitMethod) {
|
||||
throw new RuntimeException("Factory called postProcessBeforeInit after afterPropertiesSet");
|
||||
}
|
||||
if (this.postProcessedBeforeInit) {
|
||||
throw new RuntimeException("Factory called postProcessBeforeInit twice");
|
||||
}
|
||||
this.postProcessedBeforeInit = true;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
if (this.owningFactory == null) {
|
||||
throw new RuntimeException("Factory didn't call setBeanFactory before afterPropertiesSet on lifecycle bean");
|
||||
}
|
||||
if (!this.postProcessedBeforeInit) {
|
||||
throw new RuntimeException("Factory didn't call postProcessBeforeInit before afterPropertiesSet on lifecycle bean");
|
||||
}
|
||||
if (this.initedViaDeclaredInitMethod) {
|
||||
throw new RuntimeException("Factory initialized via declared init method before initializing via afterPropertiesSet");
|
||||
}
|
||||
if (this.inited) {
|
||||
throw new RuntimeException("Factory called afterPropertiesSet twice");
|
||||
}
|
||||
this.inited = true;
|
||||
}
|
||||
|
||||
public void declaredInitMethod() {
|
||||
if (!this.inited) {
|
||||
throw new RuntimeException("Factory didn't call afterPropertiesSet before declared init method");
|
||||
}
|
||||
|
||||
if (this.initedViaDeclaredInitMethod) {
|
||||
throw new RuntimeException("Factory called declared init method twice");
|
||||
}
|
||||
this.initedViaDeclaredInitMethod = true;
|
||||
}
|
||||
|
||||
public void postProcessAfterInit() {
|
||||
if (!this.inited) {
|
||||
throw new RuntimeException("Factory called postProcessAfterInit before afterPropertiesSet");
|
||||
}
|
||||
if (this.initMethodDeclared && !this.initedViaDeclaredInitMethod) {
|
||||
throw new RuntimeException("Factory called postProcessAfterInit before calling declared init method");
|
||||
}
|
||||
if (this.postProcessedAfterInit) {
|
||||
throw new RuntimeException("Factory called postProcessAfterInit twice");
|
||||
}
|
||||
this.postProcessedAfterInit = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy business method that will fail unless the factory
|
||||
* managed the bean's lifecycle correctly
|
||||
*/
|
||||
public void businessMethod() {
|
||||
if (!this.inited || (this.initMethodDeclared && !this.initedViaDeclaredInitMethod) ||
|
||||
!this.postProcessedAfterInit) {
|
||||
throw new RuntimeException("Factory didn't initialize lifecycle object correctly");
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (this.destroyed) {
|
||||
throw new IllegalStateException("Already destroyed");
|
||||
}
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
||||
public boolean isDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
|
||||
public static class PostProcessor implements BeanPostProcessor {
|
||||
|
||||
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
|
||||
if (bean instanceof ProtectedLifecycleBean) {
|
||||
((ProtectedLifecycleBean) bean).postProcessBeforeInit();
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
|
||||
if (bean instanceof ProtectedLifecycleBean) {
|
||||
((ProtectedLifecycleBean) bean).postProcessAfterInit();
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class ReverseMethodReplacer implements MethodReplacer, Serializable {
|
||||
|
||||
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable {
|
||||
String s = (String) args[0];
|
||||
return new StringBuffer(s).reverse().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
abstract class SerializableMethodReplacerCandidate extends MethodReplaceCandidate implements Serializable {
|
||||
|
||||
//public abstract Point getPoint();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 23.10.2004
|
||||
*/
|
||||
class SingleSimpleTypeConstructorBean {
|
||||
|
||||
private boolean singleBoolean;
|
||||
|
||||
private boolean secondBoolean;
|
||||
|
||||
private String testString;
|
||||
|
||||
public SingleSimpleTypeConstructorBean(boolean singleBoolean) {
|
||||
this.singleBoolean = singleBoolean;
|
||||
}
|
||||
|
||||
public SingleSimpleTypeConstructorBean(String testString, boolean secondBoolean) {
|
||||
this.testString = testString;
|
||||
this.secondBoolean = secondBoolean;
|
||||
}
|
||||
|
||||
public boolean isSingleBoolean() {
|
||||
return singleBoolean;
|
||||
}
|
||||
|
||||
public boolean isSecondBoolean() {
|
||||
return secondBoolean;
|
||||
}
|
||||
|
||||
public String getTestString() {
|
||||
return testString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -47,15 +47,15 @@
|
|||
|
||||
<bean id="parentAppCtx" class="org.springframework.context.support.ClassPathXmlApplicationContext">
|
||||
<constructor-arg>
|
||||
<value>/org/springframework/beans/factory/xml/collections.xml</value>
|
||||
<value>/org/springframework/beans/factory/xml/XmlBeanFactoryTests-collections.xml</value>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="childAppCtx" class="org.springframework.context.support.ClassPathXmlApplicationContext">
|
||||
<constructor-arg>
|
||||
<list>
|
||||
<value>/org/springframework/beans/factory/xml/constructor-arg.xml</value>
|
||||
<value>/org/springframework/beans/factory/xml/initializers.xml</value>
|
||||
<value>/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml</value>
|
||||
<value>/org/springframework/beans/factory/xml/XmlBeanFactoryTests-initializers.xml</value>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
<constructor-arg><ref bean="parentAppCtx"/></constructor-arg>
|
||||
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
<beans>
|
||||
|
||||
<import resource="recursiveImport.xml"/>
|
||||
<import resource="XmlBeanFactoryTests-recursiveImport.xml"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<beans>
|
||||
|
||||
<import resource="resourceImport.xml"/>
|
||||
<import resource="XmlBeanFactoryTests-resourceImport.xml"/>
|
||||
|
||||
<bean id="resource2" class="org.springframework.beans.ResourceTestBean">
|
||||
<constructor-arg index="0">
|
||||
|
|
@ -59,7 +59,6 @@ import org.springframework.beans.factory.support.MethodReplacer;
|
|||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
|
@ -75,14 +74,60 @@ import org.xml.sax.InputSource;
|
|||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class XmlBeanFactoryTests {
|
||||
public final class XmlBeanFactoryTests {
|
||||
|
||||
private static final Class<?> CLASS = XmlBeanFactoryTests.class;
|
||||
private static final String CLASSNAME = CLASS.getSimpleName();
|
||||
|
||||
private static final ClassPathResource AUTOWIRE_CONTEXT = classPathResource("-autowire.xml");
|
||||
private static final ClassPathResource CHILD_CONTEXT = classPathResource("-child.xml");
|
||||
private static final ClassPathResource CLASS_NOT_FOUND_CONTEXT = classPathResource("-classNotFound.xml");
|
||||
private static final ClassPathResource COMPLEX_FACTORY_CIRCLE_CONTEXT = classPathResource("-complexFactoryCircle.xml");
|
||||
private static final ClassPathResource CONSTRUCTOR_ARG_CONTEXT = classPathResource("-constructorArg.xml");
|
||||
private static final ClassPathResource CONSTRUCTOR_OVERRIDES_CONTEXT = classPathResource("-constructorOverrides.xml");
|
||||
private static final ClassPathResource DELEGATION_OVERRIDES_CONTEXT = classPathResource("-delegationOverrides.xml");
|
||||
private static final ClassPathResource DEP_CARG_AUTOWIRE_CONTEXT = classPathResource("-depCargAutowire.xml");
|
||||
private static final ClassPathResource DEP_CARG_INNER_CONTEXT = classPathResource("-depCargInner.xml");
|
||||
private static final ClassPathResource DEP_CARG_CONTEXT = classPathResource("-depCarg.xml");
|
||||
private static final ClassPathResource DEP_DEPENDSON_INNER_CONTEXT = classPathResource("-depDependsOnInner.xml");
|
||||
private static final ClassPathResource DEP_DEPENDSON_CONTEXT = classPathResource("-depDependsOn.xml");
|
||||
private static final ClassPathResource DEP_PROP = classPathResource("-depProp.xml");
|
||||
private static final ClassPathResource DEP_PROP_ABN_CONTEXT = classPathResource("-depPropAutowireByName.xml");
|
||||
private static final ClassPathResource DEP_PROP_ABT_CONTEXT = classPathResource("-depPropAutowireByType.xml");
|
||||
private static final ClassPathResource DEP_PROP_MIDDLE_CONTEXT = classPathResource("-depPropInTheMiddle.xml");
|
||||
private static final ClassPathResource DEP_PROP_INNER_CONTEXT = classPathResource("-depPropInner.xml");
|
||||
private static final ClassPathResource DEP_MATERIALIZE_CONTEXT = classPathResource("-depMaterializeThis.xml");
|
||||
private static final ClassPathResource FACTORY_CIRCLE_CONTEXT = classPathResource("-factoryCircle.xml");
|
||||
private static final ClassPathResource INITIALIZERS_CONTEXT = classPathResource("-initializers.xml");
|
||||
private static final ClassPathResource INVALID_CONTEXT = classPathResource("-invalid.xml");
|
||||
private static final ClassPathResource INVALID_NO_SUCH_METHOD_CONTEXT = classPathResource("-invalidOverridesNoSuchMethod.xml");
|
||||
private static final ClassPathResource COLLECTIONS_XSD_CONTEXT = classPathResource("-localCollectionsUsingXsd.xml");
|
||||
private static final ClassPathResource MISSING_CONTEXT = classPathResource("-missing.xml");
|
||||
private static final ClassPathResource OVERRIDES_CONTEXT = classPathResource("-overrides.xml");
|
||||
private static final ClassPathResource PARENT_CONTEXT = classPathResource("-parent.xml");
|
||||
private static final ClassPathResource NO_SUCH_FACTORY_METHOD_CONTEXT = classPathResource("-noSuchFactoryMethod.xml");
|
||||
private static final ClassPathResource RECURSIVE_IMPORT_CONTEXT = classPathResource("-recursiveImport.xml");
|
||||
private static final ClassPathResource RESOURCE_CONTEXT = classPathResource("-resource.xml");
|
||||
private static final ClassPathResource RESOURCE_IMPORT_CONTEXT = classPathResource("-resourceImport.xml");
|
||||
private static final ClassPathResource SATISFIED_ALL_DEP_CONTEXT = classPathResource("-satisfiedAllDepCheck.xml");
|
||||
private static final ClassPathResource SATISFIED_OBJECT_DEP_CONTEXT = classPathResource("-satisfiedObjectDepCheck.xml");
|
||||
private static final ClassPathResource SATISFIED_SIMPLE_DEP_CONTEXT = classPathResource("-satisfiedSimpleDepCheck.xml");
|
||||
private static final ClassPathResource TEST_WITH_DUP_NAMES_CONTEXT = classPathResource("-testWithDuplicateNames.xml");
|
||||
private static final ClassPathResource TEST_WITH_DUP_NAME_IN_ALIAS_CONTEXT = classPathResource("-testWithDuplicateNameInAlias.xml");
|
||||
private static final ClassPathResource UNSATISFIED_ALL_DEP_CONTEXT = classPathResource("-unsatisfiedAllDepCheckMissingObjects.xml");
|
||||
private static final ClassPathResource UNSATISFIED_OBJECT_DEP_CONTEXT = classPathResource("-unsatisfiedObjectDepCheck.xml");
|
||||
private static final ClassPathResource UNSATISFIED_SIMPLE_DEP_CONTEXT = classPathResource("-unsatisfiedSimpleDepCheck.xml");
|
||||
private static final ClassPathResource REFTYPES_CONTEXT = classPathResource("-reftypes.xml");
|
||||
private static final ClassPathResource DEFAULT_LAZY_CONTEXT = classPathResource("-defaultLazyInit.xml");
|
||||
private static final ClassPathResource DEFAULT_AUTOWIRE_CONTEXT = classPathResource("-defaultAutowire.xml");
|
||||
|
||||
private static ClassPathResource classPathResource(String suffix) {
|
||||
return new ClassPathResource(CLASSNAME + suffix, CLASS);
|
||||
}
|
||||
|
||||
/*
|
||||
* http://opensource.atlassian.com/projects/spring/browse/SPR-2368
|
||||
*/
|
||||
/* SPR-2368 */
|
||||
public @Test void testCollectionsReferredToAsRefLocals() throws Exception {
|
||||
XmlBeanFactory factory = new XmlBeanFactory(
|
||||
new ClassPathResource("local-collections-using-XSD.xml", getClass()));
|
||||
XmlBeanFactory factory = new XmlBeanFactory(COLLECTIONS_XSD_CONTEXT);
|
||||
factory.preInstantiateSingletons();
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +135,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
|
||||
TestBean emma = (TestBean) xbf.getBean("emma");
|
||||
TestBean georgia = (TestBean) xbf.getBean("georgia");
|
||||
|
|
@ -108,8 +153,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
Resource resource = new ClassPathResource("reftypes.xml", getClass());
|
||||
reader.loadBeanDefinitions(new EncodedResource(resource, "ISO-8859-1"));
|
||||
reader.loadBeanDefinitions(new EncodedResource(REFTYPES_CONTEXT, "ISO-8859-1"));
|
||||
|
||||
TestBean jen = (TestBean) xbf.getBean("jenny");
|
||||
TestBean dave = (TestBean) xbf.getBean("david");
|
||||
|
|
@ -125,7 +169,7 @@ public class XmlBeanFactoryTests {
|
|||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
InputStream inputStream = getClass().getResourceAsStream("reftypes.xml");
|
||||
InputStream inputStream = getClass().getResourceAsStream(REFTYPES_CONTEXT.getPath());
|
||||
try {
|
||||
reader.loadBeanDefinitions(new InputSource(inputStream));
|
||||
}
|
||||
|
|
@ -187,7 +231,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
|
||||
// Let's create the outer bean named "innerBean",
|
||||
// to check whether it doesn't create any conflicts
|
||||
|
|
@ -220,7 +264,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
|
||||
try {
|
||||
xbf.getBean("failsOnInnerBean");
|
||||
|
|
@ -244,8 +288,8 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testSingletonInheritanceFromParentFactorySingleton() throws Exception {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
assertEquals(TestBean.class, child.getType("inheritsFromParentFactory"));
|
||||
TestBean inherits = (TestBean) child.getBean("inheritsFromParentFactory");
|
||||
// Name property value is overridden
|
||||
|
|
@ -257,8 +301,8 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testInheritanceWithDifferentClass() throws Exception {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
|
||||
DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithDifferentClass");
|
||||
// Name property value is overridden
|
||||
|
|
@ -269,8 +313,8 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testInheritanceWithClass() throws Exception {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
|
||||
DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithClass");
|
||||
// Name property value is overridden
|
||||
|
|
@ -281,8 +325,8 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testPrototypeInheritanceFromParentFactoryPrototype() throws Exception {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
assertEquals(TestBean.class, child.getType("prototypeInheritsFromParentFactoryPrototype"));
|
||||
TestBean inherits = (TestBean) child.getBean("prototypeInheritsFromParentFactoryPrototype");
|
||||
// Name property value is overridden
|
||||
|
|
@ -298,8 +342,8 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testPrototypeInheritanceFromParentFactorySingleton() throws Exception {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
TestBean inherits = (TestBean) child.getBean("protoypeInheritsFromParentFactorySingleton");
|
||||
// Name property value is overridden
|
||||
assertTrue(inherits.getName().equals("prototypeOverridesInheritedSingleton"));
|
||||
|
|
@ -316,7 +360,7 @@ public class XmlBeanFactoryTests {
|
|||
public @Test void testAutowireModeNotInherited() {
|
||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
||||
reader.loadBeanDefinitions(OVERRIDES_CONTEXT);
|
||||
|
||||
TestBean david = (TestBean)xbf.getBean("magicDavid");
|
||||
// the parent bean is autowiring
|
||||
|
|
@ -328,7 +372,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testAbstractParentBeans() {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
parent.preInstantiateSingletons();
|
||||
assertTrue(parent.isSingleton("inheritedTestBeanWithoutClass"));
|
||||
|
||||
|
|
@ -352,7 +396,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testDependenciesMaterializeThis() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("dependenciesMaterializeThis.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(DEP_MATERIALIZE_CONTEXT);
|
||||
|
||||
assertEquals(2, xbf.getBeansOfType(DummyBo.class, true, false).size());
|
||||
assertEquals(3, xbf.getBeansOfType(DummyBo.class, true, true).size());
|
||||
|
|
@ -369,8 +413,8 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testChildOverridesParentBean() throws Exception {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
TestBean inherits = (TestBean) child.getBean("inheritedTestBean");
|
||||
// Name property value is overridden
|
||||
assertTrue(inherits.getName().equals("overrideParentBean"));
|
||||
|
|
@ -385,8 +429,8 @@ public class XmlBeanFactoryTests {
|
|||
* If a singleton does this the factory will fail to load.
|
||||
*/
|
||||
public @Test void testBogusParentageFromParentFactory() throws Exception {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
try {
|
||||
child.getBean("bogusParent", TestBean.class);
|
||||
fail();
|
||||
|
|
@ -404,8 +448,8 @@ public class XmlBeanFactoryTests {
|
|||
* instances even if derived from a prototype
|
||||
*/
|
||||
public @Test void testSingletonInheritsFromParentFactoryPrototype() throws Exception {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
TestBean inherits = (TestBean) child.getBean("singletonInheritsFromParentFactoryPrototype");
|
||||
// Name property value is overriden
|
||||
assertTrue(inherits.getName().equals("prototype-override"));
|
||||
|
|
@ -416,16 +460,16 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testSingletonFromParent() {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
TestBean beanFromParent = (TestBean) parent.getBean("inheritedTestBeanSingleton");
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
TestBean beanFromChild = (TestBean) child.getBean("inheritedTestBeanSingleton");
|
||||
assertTrue("singleton from parent and child is the same", beanFromParent == beanFromChild);
|
||||
}
|
||||
|
||||
public @Test void testNestedPropertyValue() {
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT);
|
||||
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent);
|
||||
IndexedTestBean bean = (IndexedTestBean) child.getBean("indexedTestBean");
|
||||
assertEquals("name applied correctly", "myname", bean.getArray()[0].getName());
|
||||
}
|
||||
|
|
@ -434,7 +478,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
TestBean jenny = (TestBean) xbf.getBean("jenny");
|
||||
TestBean david = (TestBean) xbf.getBean("david");
|
||||
TestBean ego = (TestBean) xbf.getBean("ego");
|
||||
|
|
@ -451,7 +495,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
xbf.getBean("egoBridge");
|
||||
TestBean complexEgo = (TestBean) xbf.getBean("complexEgo");
|
||||
assertTrue("Correct circular reference", complexEgo.getSpouse().getSpouse() == complexEgo);
|
||||
|
|
@ -461,7 +505,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
TestBean ego1 = (TestBean) xbf.getBean("ego1");
|
||||
assertTrue("Correct circular reference", ego1.getSpouse().getSpouse() == ego1);
|
||||
TestBean ego3 = (TestBean) xbf.getBean("ego3");
|
||||
|
|
@ -473,7 +517,7 @@ public class XmlBeanFactoryTests {
|
|||
xbf.setAllowCircularReferences(false);
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
try {
|
||||
xbf.getBean("jenny");
|
||||
fail("Should have thrown BeanCreationException");
|
||||
|
|
@ -487,7 +531,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
xbf.addBeanPostProcessor(new WrappingPostProcessor());
|
||||
try {
|
||||
xbf.getBean("jenny");
|
||||
|
|
@ -503,7 +547,7 @@ public class XmlBeanFactoryTests {
|
|||
xbf.setAllowRawInjectionDespiteWrapping(true);
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
|
||||
xbf.addBeanPostProcessor(new WrappingPostProcessor());
|
||||
|
||||
ITestBean jenny = (ITestBean) xbf.getBean("jenny");
|
||||
|
|
@ -519,19 +563,19 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testFactoryReferenceCircle() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("factoryCircle.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(FACTORY_CIRCLE_CONTEXT);
|
||||
TestBean tb = (TestBean) xbf.getBean("singletonFactory");
|
||||
DummyFactory db = (DummyFactory) xbf.getBean("&singletonFactory");
|
||||
assertTrue(tb == db.getOtherTestBean());
|
||||
}
|
||||
|
||||
public @Test void testFactoryReferenceWithDoublePrefix() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("factoryCircle.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(FACTORY_CIRCLE_CONTEXT);
|
||||
assertThat(xbf.getBean("&&singletonFactory"), instanceOf(DummyFactory.class));
|
||||
}
|
||||
|
||||
public @Test void testComplexFactoryReferenceCircle() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("complexFactoryCircle.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(COMPLEX_FACTORY_CIRCLE_CONTEXT);
|
||||
xbf.getBean("proxy1");
|
||||
// check that unused instances from autowiring got removed
|
||||
assertEquals(5, xbf.getSingletonCount());
|
||||
|
|
@ -542,7 +586,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testNoSuchFactoryBeanMethod() {
|
||||
try {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("no-such-factory-method.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(NO_SUCH_FACTORY_METHOD_CONTEXT);
|
||||
assertNotNull(xbf.getBean("defaultTestBean"));
|
||||
fail("Should not get invalid bean");
|
||||
}
|
||||
|
|
@ -552,7 +596,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testInitMethodIsInvoked() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT);
|
||||
DoubleInitializer in = (DoubleInitializer) xbf.getBean("init-method1");
|
||||
// Initializer should have doubled value
|
||||
assertEquals(14, in.getNum());
|
||||
|
|
@ -562,7 +606,7 @@ public class XmlBeanFactoryTests {
|
|||
* Test that if a custom initializer throws an exception, it's handled correctly
|
||||
*/
|
||||
public @Test void testInitMethodThrowsException() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT);
|
||||
try {
|
||||
xbf.getBean("init-method2");
|
||||
fail();
|
||||
|
|
@ -575,7 +619,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testNoSuchInitMethod() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT);
|
||||
try {
|
||||
xbf.getBean("init-method3");
|
||||
fail();
|
||||
|
|
@ -593,7 +637,7 @@ public class XmlBeanFactoryTests {
|
|||
*/
|
||||
public @Test void testInitializingBeanAndInitMethod() throws Exception {
|
||||
InitAndIB.constructed = false;
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT);
|
||||
assertFalse(InitAndIB.constructed);
|
||||
xbf.preInstantiateSingletons();
|
||||
assertFalse(InitAndIB.constructed);
|
||||
|
|
@ -612,7 +656,7 @@ public class XmlBeanFactoryTests {
|
|||
*/
|
||||
public @Test void testInitializingBeanAndSameInitMethod() throws Exception {
|
||||
InitAndIB.constructed = false;
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT);
|
||||
assertFalse(InitAndIB.constructed);
|
||||
xbf.preInstantiateSingletons();
|
||||
assertFalse(InitAndIB.constructed);
|
||||
|
|
@ -628,7 +672,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testDefaultLazyInit() throws Exception {
|
||||
InitAndIB.constructed = false;
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("default-lazy-init.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(DEFAULT_LAZY_CONTEXT);
|
||||
assertFalse(InitAndIB.constructed);
|
||||
xbf.preInstantiateSingletons();
|
||||
assertTrue(InitAndIB.constructed);
|
||||
|
|
@ -642,7 +686,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testNoSuchXmlFile() throws Exception {
|
||||
try {
|
||||
new XmlBeanFactory(new ClassPathResource("missing.xml", getClass()));
|
||||
new XmlBeanFactory(MISSING_CONTEXT);
|
||||
fail("Must not create factory from missing XML");
|
||||
}
|
||||
catch (BeanDefinitionStoreException expected) {
|
||||
|
|
@ -651,7 +695,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testInvalidXmlFile() throws Exception {
|
||||
try {
|
||||
new XmlBeanFactory(new ClassPathResource("invalid.xml", getClass()));
|
||||
new XmlBeanFactory(INVALID_CONTEXT);
|
||||
fail("Must not create factory from invalid XML");
|
||||
}
|
||||
catch (BeanDefinitionStoreException expected) {
|
||||
|
|
@ -660,7 +704,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testUnsatisfiedObjectDependencyCheck() throws Exception {
|
||||
try {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedObjectDependencyCheck.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(UNSATISFIED_OBJECT_DEP_CONTEXT);
|
||||
xbf.getBean("a", DependenciesBean.class);
|
||||
fail("Must have thrown an UnsatisfiedDependencyException");
|
||||
}
|
||||
|
|
@ -670,7 +714,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testUnsatisfiedSimpleDependencyCheck() throws Exception {
|
||||
try {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedSimpleDependencyCheck.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(UNSATISFIED_SIMPLE_DEP_CONTEXT);
|
||||
xbf.getBean("a", DependenciesBean.class);
|
||||
fail("Must have thrown an UnsatisfiedDependencyException");
|
||||
}
|
||||
|
|
@ -679,21 +723,21 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testSatisfiedObjectDependencyCheck() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedObjectDependencyCheck.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(SATISFIED_OBJECT_DEP_CONTEXT);
|
||||
DependenciesBean a = (DependenciesBean) xbf.getBean("a");
|
||||
assertNotNull(a.getSpouse());
|
||||
assertEquals(xbf, a.getBeanFactory());
|
||||
}
|
||||
|
||||
public @Test void testSatisfiedSimpleDependencyCheck() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedSimpleDependencyCheck.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(SATISFIED_SIMPLE_DEP_CONTEXT);
|
||||
DependenciesBean a = (DependenciesBean) xbf.getBean("a");
|
||||
assertEquals(a.getAge(), 33);
|
||||
}
|
||||
|
||||
public @Test void testUnsatisfiedAllDependencyCheck() throws Exception {
|
||||
try {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedAllDependencyCheckMissingObjects.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(UNSATISFIED_ALL_DEP_CONTEXT);
|
||||
xbf.getBean("a", DependenciesBean.class);
|
||||
fail("Must have thrown an UnsatisfiedDependencyException");
|
||||
}
|
||||
|
|
@ -702,7 +746,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testSatisfiedAllDependencyCheck() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedAllDependencyCheck.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(SATISFIED_ALL_DEP_CONTEXT);
|
||||
DependenciesBean a = (DependenciesBean) xbf.getBean("a");
|
||||
assertEquals(a.getAge(), 33);
|
||||
assertNotNull(a.getName());
|
||||
|
|
@ -710,14 +754,14 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testAutowire() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("autowire.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(AUTOWIRE_CONTEXT);
|
||||
TestBean spouse = new TestBean("kerry", 0);
|
||||
xbf.registerSingleton("spouse", spouse);
|
||||
doTestAutowire(xbf);
|
||||
}
|
||||
|
||||
public @Test void testAutowireWithParent() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("autowire.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(AUTOWIRE_CONTEXT);
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.addPropertyValue("name", "kerry");
|
||||
|
|
@ -774,7 +818,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testAutowireWithDefault() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("default-autowire.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(DEFAULT_AUTOWIRE_CONTEXT);
|
||||
|
||||
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
|
||||
// should have been autowired
|
||||
|
|
@ -795,7 +839,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testAutowireByConstructor() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
ConstructorDependenciesBean rod1 = (ConstructorDependenciesBean) xbf.getBean("rod1");
|
||||
TestBean kerry = (TestBean) xbf.getBean("kerry2");
|
||||
// should have been autowired
|
||||
|
|
@ -831,7 +875,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testAutowireByConstructorWithSimpleValues() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
|
||||
ConstructorDependenciesBean rod5 = (ConstructorDependenciesBean) xbf.getBean("rod5");
|
||||
TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
|
||||
|
|
@ -859,7 +903,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testRelatedCausesFromConstructorResolution() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
|
||||
try {
|
||||
xbf.getBean("rod2Accessor");
|
||||
|
|
@ -872,7 +916,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testConstructorArgResolution() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
|
||||
TestBean kerry2 = (TestBean) xbf.getBean("kerry2");
|
||||
|
||||
|
|
@ -914,13 +958,13 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testConstructorArgWithSingleMatch() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
File file = (File) xbf.getBean("file");
|
||||
assertEquals(File.separator + "test", file.getPath());
|
||||
}
|
||||
|
||||
public @Test void testThrowsExceptionOnTooManyArguments() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
try {
|
||||
xbf.getBean("rod7", ConstructorDependenciesBean.class);
|
||||
fail("Should have thrown BeanCreationException");
|
||||
|
|
@ -930,7 +974,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testThrowsExceptionOnAmbiguousResolution() throws Exception {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
try {
|
||||
xbf.getBean("rod8", ConstructorDependenciesBean.class);
|
||||
fail("Must have thrown UnsatisfiedDependencyException");
|
||||
|
|
@ -940,53 +984,53 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testDependsOn() {
|
||||
doTestDependencies("dependencies-dependsOn.xml", 1);
|
||||
doTestDependencies(DEP_DEPENDSON_CONTEXT, 1);
|
||||
}
|
||||
|
||||
public @Test void testDependsOnInInnerBean() {
|
||||
doTestDependencies("dependencies-dependsOn-inner.xml", 4);
|
||||
doTestDependencies(DEP_DEPENDSON_INNER_CONTEXT, 4);
|
||||
}
|
||||
|
||||
public @Test void testDependenciesThroughConstructorArguments() {
|
||||
doTestDependencies("dependencies-carg.xml", 1);
|
||||
doTestDependencies(DEP_CARG_CONTEXT, 1);
|
||||
}
|
||||
|
||||
public @Test void testDependenciesThroughConstructorArgumentAutowiring() {
|
||||
doTestDependencies("dependencies-carg-autowire.xml", 1);
|
||||
doTestDependencies(DEP_CARG_AUTOWIRE_CONTEXT, 1);
|
||||
}
|
||||
|
||||
public @Test void testDependenciesThroughConstructorArgumentsInInnerBean() {
|
||||
doTestDependencies("dependencies-carg-inner.xml", 1);
|
||||
doTestDependencies(DEP_CARG_INNER_CONTEXT, 1);
|
||||
}
|
||||
|
||||
public @Test void testDependenciesThroughProperties() {
|
||||
doTestDependencies("dependencies-prop.xml", 1);
|
||||
doTestDependencies(DEP_PROP, 1);
|
||||
}
|
||||
|
||||
public @Test void testDependenciesThroughPropertiesWithInTheMiddle() {
|
||||
doTestDependencies("dependencies-prop-inTheMiddle.xml", 1);
|
||||
doTestDependencies(DEP_PROP_MIDDLE_CONTEXT, 1);
|
||||
}
|
||||
|
||||
public @Test void testDependenciesThroughPropertyAutowiringByName() {
|
||||
doTestDependencies("dependencies-prop-autowireByName.xml", 1);
|
||||
doTestDependencies(DEP_PROP_ABN_CONTEXT, 1);
|
||||
}
|
||||
|
||||
public @Test void testDependenciesThroughPropertyAutowiringByType() {
|
||||
doTestDependencies("dependencies-prop-autowireByType.xml", 1);
|
||||
doTestDependencies(DEP_PROP_ABT_CONTEXT, 1);
|
||||
}
|
||||
|
||||
public @Test void testDependenciesThroughPropertiesInInnerBean() {
|
||||
doTestDependencies("dependencies-prop-inner.xml", 1);
|
||||
doTestDependencies(DEP_PROP_INNER_CONTEXT, 1);
|
||||
}
|
||||
|
||||
private void doTestDependencies(String filename, int nrOfHoldingBeans) {
|
||||
private void doTestDependencies(ClassPathResource resource, int nrOfHoldingBeans) {
|
||||
PreparingBean1.prepared = false;
|
||||
PreparingBean1.destroyed = false;
|
||||
PreparingBean2.prepared = false;
|
||||
PreparingBean2.destroyed = false;
|
||||
DependingBean.destroyCount = 0;
|
||||
HoldingBean.destroyCount = 0;
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource(filename, getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(resource);
|
||||
xbf.preInstantiateSingletons();
|
||||
xbf.destroySingletons();
|
||||
assertTrue(PreparingBean1.prepared);
|
||||
|
|
@ -1006,7 +1050,7 @@ public class XmlBeanFactoryTests {
|
|||
* must rather only be picked up when the bean is instantiated.
|
||||
*/
|
||||
public @Test void testClassNotFoundWithDefaultBeanClassLoader() {
|
||||
BeanFactory factory = new XmlBeanFactory(new ClassPathResource("classNotFound.xml", getClass()));
|
||||
BeanFactory factory = new XmlBeanFactory(CLASS_NOT_FOUND_CONTEXT);
|
||||
// cool, no errors, so the rubbish class name in the bean def was not resolved
|
||||
try {
|
||||
// let's resolve the bean definition; must blow up
|
||||
|
|
@ -1023,12 +1067,12 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
||||
reader.setBeanClassLoader(null);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("classNotFound.xml", getClass()));
|
||||
reader.loadBeanDefinitions(CLASS_NOT_FOUND_CONTEXT);
|
||||
assertEquals("WhatALotOfRubbish", bf.getBeanDefinition("classNotFound").getBeanClassName());
|
||||
}
|
||||
|
||||
public @Test void testResourceAndInputStream() throws IOException {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("resource.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(RESOURCE_CONTEXT);
|
||||
// comes from "resourceImport.xml"
|
||||
ResourceTestBean resource1 = (ResourceTestBean) xbf.getBean("resource1");
|
||||
// comes from "resource.xml"
|
||||
|
|
@ -1050,8 +1094,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testClassPathResourceWithImport() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(
|
||||
new ClassPathResource("org/springframework/beans/factory/xml/resource.xml"));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(RESOURCE_CONTEXT);
|
||||
// comes from "resourceImport.xml"
|
||||
xbf.getBean("resource1", ResourceTestBean.class);
|
||||
// comes from "resource.xml"
|
||||
|
|
@ -1059,7 +1102,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testUrlResourceWithImport() {
|
||||
URL url = getClass().getResource("resource.xml");
|
||||
URL url = getClass().getResource(RESOURCE_CONTEXT.getPath());
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new UrlResource(url));
|
||||
// comes from "resourceImport.xml"
|
||||
xbf.getBean("resource1", ResourceTestBean.class);
|
||||
|
|
@ -1068,7 +1111,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testFileSystemResourceWithImport() {
|
||||
String file = getClass().getResource("resource.xml").getFile();
|
||||
String file = getClass().getResource(RESOURCE_CONTEXT.getPath()).getFile();
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new FileSystemResource(file));
|
||||
// comes from "resourceImport.xml"
|
||||
xbf.getBean("resource1", ResourceTestBean.class);
|
||||
|
|
@ -1078,7 +1121,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testRecursiveImport() {
|
||||
try {
|
||||
new XmlBeanFactory(new ClassPathResource("org/springframework/beans/factory/xml/recursiveImport.xml"));
|
||||
new XmlBeanFactory(RECURSIVE_IMPORT_CONTEXT);
|
||||
fail("Should have thrown BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
|
|
@ -1091,7 +1134,7 @@ public class XmlBeanFactoryTests {
|
|||
public @Test void testLookupOverrideMethodsWithSetterInjection() {
|
||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
||||
reader.loadBeanDefinitions(OVERRIDES_CONTEXT);
|
||||
|
||||
testLookupOverrideMethodsWithSetterInjection(xbf, "overrideOneMethod", true);
|
||||
// Should work identically on subclass definition, in which lookup
|
||||
|
|
@ -1156,7 +1199,7 @@ public class XmlBeanFactoryTests {
|
|||
public @Test void testReplaceMethodOverrideWithSetterInjection() {
|
||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("delegationOverrides.xml", getClass()));
|
||||
reader.loadBeanDefinitions(DELEGATION_OVERRIDES_CONTEXT);
|
||||
|
||||
OverrideOneMethod oom = (OverrideOneMethod) xbf.getBean("overrideOneMethod");
|
||||
|
||||
|
|
@ -1203,7 +1246,7 @@ public class XmlBeanFactoryTests {
|
|||
public @Test void testLookupOverrideOneMethodWithConstructorInjection() {
|
||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("constructorOverrides.xml", getClass()));
|
||||
reader.loadBeanDefinitions(CONSTRUCTOR_OVERRIDES_CONTEXT);
|
||||
|
||||
ConstructorInjectedOverrides cio = (ConstructorInjectedOverrides) xbf.getBean("constructorOverrides");
|
||||
|
||||
|
|
@ -1227,7 +1270,7 @@ public class XmlBeanFactoryTests {
|
|||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
try {
|
||||
reader.loadBeanDefinitions(new ClassPathResource("invalidOverridesNoSuchMethod.xml", getClass()));
|
||||
reader.loadBeanDefinitions(INVALID_NO_SUCH_METHOD_CONTEXT);
|
||||
xbf.getBean("constructorOverrides");
|
||||
fail("Shouldn't allow override of bogus method");
|
||||
}
|
||||
|
|
@ -1253,7 +1296,7 @@ public class XmlBeanFactoryTests {
|
|||
public void BUGtestSerializableMethodReplacerAndSuperclass() throws IOException, ClassNotFoundException {
|
||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("delegationOverrides.xml", getClass()));
|
||||
reader.loadBeanDefinitions(DELEGATION_OVERRIDES_CONTEXT);
|
||||
SerializableMethodReplacerCandidate s = (SerializableMethodReplacerCandidate) xbf.getBean("serializableReplacer");
|
||||
String forwards = "this is forwards";
|
||||
String backwards = new StringBuffer(forwards).reverse().toString();
|
||||
|
|
@ -1266,14 +1309,14 @@ public class XmlBeanFactoryTests {
|
|||
public @Test void testInnerBeanInheritsScopeFromConcreteChildDefinition() {
|
||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
||||
reader.loadBeanDefinitions(OVERRIDES_CONTEXT);
|
||||
TestBean jenny = (TestBean) xbf.getBean("jennyChild");
|
||||
assertEquals(1, jenny.getFriends().size());
|
||||
assertTrue(jenny.getFriends().iterator().next() instanceof TestBean);
|
||||
}
|
||||
|
||||
public @Test void testConstructorArgWithSingleSimpleTypeMatch() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
|
||||
SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBoolean");
|
||||
assertTrue(bean.isSingleBoolean());
|
||||
|
|
@ -1283,7 +1326,7 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testConstructorArgWithDoubleSimpleTypeMatch() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
|
||||
SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBooleanAndString");
|
||||
assertTrue(bean.isSecondBoolean());
|
||||
|
|
@ -1295,14 +1338,14 @@ public class XmlBeanFactoryTests {
|
|||
}
|
||||
|
||||
public @Test void testDoubleBooleanAutowire() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
DoubleBooleanConstructorBean bean = (DoubleBooleanConstructorBean) xbf.getBean("beanWithDoubleBoolean");
|
||||
assertEquals(Boolean.TRUE, bean.boolean1);
|
||||
assertEquals(Boolean.FALSE, bean.boolean2);
|
||||
}
|
||||
|
||||
public @Test void testDoubleBooleanAutowireWithIndex() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
|
||||
DoubleBooleanConstructorBean bean = (DoubleBooleanConstructorBean) xbf.getBean("beanWithDoubleBooleanAndIndex");
|
||||
assertEquals(Boolean.FALSE, bean.boolean1);
|
||||
assertEquals(Boolean.TRUE, bean.boolean2);
|
||||
|
|
@ -1310,7 +1353,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testWithDuplicateName() throws Exception {
|
||||
try {
|
||||
new XmlBeanFactory(new ClassPathResource("testWithDuplicateNames.xml", getClass()));
|
||||
new XmlBeanFactory(TEST_WITH_DUP_NAMES_CONTEXT);
|
||||
fail("Duplicate name not detected");
|
||||
}
|
||||
catch (BeansException ex) {
|
||||
|
|
@ -1320,7 +1363,7 @@ public class XmlBeanFactoryTests {
|
|||
|
||||
public @Test void testWithDuplicateNameInAlias() throws Exception {
|
||||
try {
|
||||
new XmlBeanFactory(new ClassPathResource("testWithDuplicateNameInAlias.xml", getClass()));
|
||||
new XmlBeanFactory(TEST_WITH_DUP_NAME_IN_ALIAS_CONTEXT);
|
||||
fail("Duplicate name not detected");
|
||||
}
|
||||
catch (BeansException e) {
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
<?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>
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?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 default-lazy-init="true" default-autowire="constructor" default-dependency-check="objects"
|
||||
default-init-method="myInit" default-destroy-method="myDestroy" default-merge="true">
|
||||
|
||||
<import resource="beanEventsImported.xml"/>
|
||||
|
||||
<alias name="testBean" alias="testBeanAlias1"/>
|
||||
|
||||
<alias name="testBean" alias="testBeanAlias2"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean">
|
||||
<constructor-arg type="java.lang.String" value="Rob Harrop"/>
|
||||
<property name="friends">
|
||||
<ref bean="testBean2"/>
|
||||
</property>
|
||||
<property name="doctor">
|
||||
<bean class="org.springframework.beans.NestedTestBean">
|
||||
<constructor-arg type="java.lang.String" value="ACME"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="testBean2" class="org.springframework.beans.TestBean">
|
||||
<property name="name" value="Juergen Hoeller"/>
|
||||
<property name="spouse">
|
||||
<bean class="org.springframework.beans.TestBean">
|
||||
<property name="name" value="Eva Schallmeiner"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?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>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?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 class="org.springframework.beans.factory.xml.GeneratedNameBean">
|
||||
<property name="child">
|
||||
<bean class="org.springframework.beans.factory.xml.GeneratedNameBean"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.xml.GeneratedNameBean">
|
||||
<property name="child">
|
||||
<bean class="org.springframework.beans.factory.xml.GeneratedNameBean"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,205 +0,0 @@
|
|||
<?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="parentWithList" class="org.springframework.beans.TestBean">
|
||||
<property name="someList">
|
||||
<list>
|
||||
<value>Rob Harrop</value>
|
||||
<value>Rod Johnson</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithList" parent="parentWithList">
|
||||
<property name="someList">
|
||||
<list merge="true">
|
||||
<value>Juergen Hoeller</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithListOfRefs" parent="parentWithList">
|
||||
<property name="someList">
|
||||
<list merge="true">
|
||||
<bean class="org.springframework.beans.TestBean"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="parentWithSet" class="org.springframework.beans.TestBean">
|
||||
<property name="someSet">
|
||||
<set>
|
||||
<value>Rob Harrop</value>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithSet" parent="parentWithSet">
|
||||
<property name="someSet">
|
||||
<set merge="true">
|
||||
<value>Sally Greenwood</value>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithSetOfRefs" parent="parentWithSet">
|
||||
<property name="someSet">
|
||||
<set merge="true">
|
||||
<bean class="org.springframework.beans.TestBean">
|
||||
<property name="name" value="Sally"/>
|
||||
</bean>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="parentWithMap" class="org.springframework.beans.TestBean">
|
||||
<property name="someMap">
|
||||
<map>
|
||||
<entry key="Rob" value="Sall"/>
|
||||
<entry key="Juergen" value="Eva"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithMap" parent="parentWithMap">
|
||||
<property name="someMap">
|
||||
<map merge="true">
|
||||
<entry key="Rod" value="Kerry"/>
|
||||
<entry key="Rob" value="Sally"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithMapOfRefs" parent="parentWithMap">
|
||||
<property name="someMap">
|
||||
<map merge="true">
|
||||
<entry key="Rob">
|
||||
<bean class="org.springframework.beans.TestBean">
|
||||
<property name="name" value="Sally"/>
|
||||
</bean>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="parentWithProps" class="org.springframework.beans.TestBean">
|
||||
<property name="someProperties">
|
||||
<props>
|
||||
<prop key="Rob">Sall</prop>
|
||||
<prop key="Rod">Kerry</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithProps" parent="parentWithProps">
|
||||
<property name="someProperties">
|
||||
<props merge="true">
|
||||
<prop key="Juergen">Eva</prop>
|
||||
<prop key="Rob">Sally</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="parentWithListInConstructor" class="org.springframework.beans.TestBean">
|
||||
<constructor-arg index="0">
|
||||
<list>
|
||||
<value>Rob Harrop</value>
|
||||
<value>Rod Johnson</value>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithListInConstructor" parent="parentWithListInConstructor">
|
||||
<constructor-arg index="0">
|
||||
<list merge="true">
|
||||
<value>Juergen Hoeller</value>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithListOfRefsInConstructor" parent="parentWithListInConstructor">
|
||||
<constructor-arg index="0">
|
||||
<list merge="true">
|
||||
<bean class="org.springframework.beans.TestBean"/>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="parentWithSetInConstructor" class="org.springframework.beans.TestBean">
|
||||
<constructor-arg index="0">
|
||||
<set>
|
||||
<value>Rob Harrop</value>
|
||||
</set>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithSetInConstructor" parent="parentWithSetInConstructor">
|
||||
<constructor-arg index="0">
|
||||
<set merge="true">
|
||||
<value>Sally Greenwood</value>
|
||||
</set>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithSetOfRefsInConstructor" parent="parentWithSetInConstructor">
|
||||
<constructor-arg index="0">
|
||||
<set merge="true">
|
||||
<bean class="org.springframework.beans.TestBean">
|
||||
<property name="name" value="Sally"/>
|
||||
</bean>
|
||||
</set>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="parentWithMapInConstructor" class="org.springframework.beans.TestBean">
|
||||
<constructor-arg index="0">
|
||||
<map>
|
||||
<entry key="Rob" value="Sall"/>
|
||||
<entry key="Juergen" value="Eva"/>
|
||||
</map>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithMapInConstructor" parent="parentWithMapInConstructor">
|
||||
<constructor-arg index="0">
|
||||
<map merge="true">
|
||||
<entry key="Rod" value="Kerry"/>
|
||||
<entry key="Rob" value="Sally"/>
|
||||
</map>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithMapOfRefsInConstructor" parent="parentWithMapInConstructor">
|
||||
<constructor-arg index="0">
|
||||
<map merge="true">
|
||||
<entry key="Rob">
|
||||
<bean class="org.springframework.beans.TestBean">
|
||||
<property name="name" value="Sally"/>
|
||||
</bean>
|
||||
</entry>
|
||||
</map>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="parentWithPropsInConstructor" class="org.springframework.beans.TestBean">
|
||||
<constructor-arg index="0">
|
||||
<props>
|
||||
<prop key="Rob">Sall</prop>
|
||||
<prop key="Rod">Kerry</prop>
|
||||
</props>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="childWithPropsInConstructor" parent="parentWithPropsInConstructor">
|
||||
<constructor-arg index="0">
|
||||
<props merge="true">
|
||||
<prop key="Juergen">Eva</prop>
|
||||
<prop key="Rob">Sally</prop>
|
||||
</props>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?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="testBean" class="org.springframework.beans.TestBean">
|
||||
<property name="someList">
|
||||
<list value-type="java.lang.Integer">
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>3</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="someSet">
|
||||
<set value-type="java.lang.Integer">
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>3</value>
|
||||
</set>
|
||||
</property>
|
||||
<property name="someMap">
|
||||
<map key-type="java.lang.Integer" value-type="java.lang.Boolean">
|
||||
<entry key="1" value="true"/>
|
||||
<entry key="2" value="false"/>
|
||||
<entry key="3" value="false"/>
|
||||
<entry key="4" value="true"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="testBean2" class="org.springframework.beans.TestBean">
|
||||
<property name="someMap">
|
||||
<map key-type="java.lang.Integer" value-type="java.lang.Boolean">
|
||||
<entry>
|
||||
<key>
|
||||
<value>1</value>
|
||||
</key>
|
||||
<value>true</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>
|
||||
<value>2</value>
|
||||
</key>
|
||||
<value>false</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>
|
||||
<value>3</value>
|
||||
</key>
|
||||
<value>false</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>
|
||||
<value>4</value>
|
||||
</key>
|
||||
<value>true</value>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
<?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 default-init-method="init" default-destroy-method="destroy">
|
||||
|
||||
<bean id="lifecycleAware" class="org.springframework.beans.factory.xml.DefaultLifecycleMethodsTests$LifecycleAwareBean"/>
|
||||
|
||||
<bean id="lifecycleMethodsDisabled" class="org.springframework.beans.factory.xml.DefaultLifecycleMethodsTests$LifecycleAwareBean"
|
||||
init-method="" destroy-method=""/>
|
||||
|
||||
<bean id="overrideLifecycleMethods" class="org.springframework.beans.factory.xml.DefaultLifecycleMethodsTests$LifecycleAwareBean"
|
||||
init-method="customInit" destroy-method="customDestroy"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?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 default-init-method="foo" default-destroy-method="bar">
|
||||
|
||||
<bean id="foo" class="org.springframework.beans.factory.xml.DefaultLifecycleMethodsTests$LifecycleAwareBean"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<?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="invalidFactory" class="org.springframework.beans.factory.DummyFactory" scope="prototype">
|
||||
<property name="singleton"><value>false</value></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?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.0.xsd">
|
||||
|
||||
<foobar/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?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.0.xsd">
|
||||
|
||||
<bean xml:lang="en" id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="fooBean" class="org.springframework.beans.TestBean">
|
||||
<property name="spouse">
|
||||
<bean class="org.springframework.beans.TestBean"/>
|
||||
</property>
|
||||
<property name="friends">
|
||||
<list>
|
||||
<bean class="org.springframework.beans.TestBean"/>
|
||||
<bean class="org.springframework.beans.TestBean"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" p:name="Rob Harrop" p:spouse-ref="sally">
|
||||
<property name="age" value="24"/>
|
||||
</bean>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean" p:name="Sally Greenwood" p:spouse-ref="rob"/>
|
||||
|
||||
<bean id="sally2" class="org.springframework.beans.TestBean">
|
||||
<property name="spouse">
|
||||
<bean id="rob2" class="org.springframework.beans.TestBean" p:name="Rob Harrop" p:spouse-ref="sally2">
|
||||
<property name="age" value="24"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="derivedSally" class="org.springframework.beans.DerivedTestBean" p:name="Sally Greenwood" p:spouseRef="r"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" p:name="Rob Harrop" p:spouse-ref="sally">
|
||||
<property name="name" value="Rob Harrop"/>
|
||||
</bean>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean" p:name="Sally Greenwood" p:spouse-ref="rob"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
<?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="validEmptyWithDescription" class="org.springframework.beans.TestBean">
|
||||
<description>
|
||||
I have no properties and I'm happy without them.
|
||||
</description>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Check automatic creation of alias, to allow for names that are illegal as XML ids.
|
||||
-->
|
||||
<bean id="aliased" class=" org.springframework.beans.TestBean " name="myalias">
|
||||
<property name="name"><value>aliased</value></property>
|
||||
</bean>
|
||||
|
||||
<alias name="aliased" alias="youralias"/>
|
||||
|
||||
<alias name="multiAliased" alias="alias3"/>
|
||||
|
||||
<bean id="multiAliased" class="org.springframework.beans.TestBean" name="alias1,alias2">
|
||||
<property name="name"><value>aliased</value></property>
|
||||
</bean>
|
||||
|
||||
<alias name="multiAliased" alias="alias4"/>
|
||||
|
||||
<bean class="org.springframework.beans.TestBean" name="aliasWithoutId1,aliasWithoutId2,aliasWithoutId3">
|
||||
<property name="name"><value>aliased</value></property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.TestBean">
|
||||
<property name="name"><null/></property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
|
||||
|
||||
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
|
||||
|
||||
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
|
||||
|
||||
<bean id="rod" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value><!-- a comment -->Rod</value></property>
|
||||
<property name="age"><value>31</value></property>
|
||||
<property name="spouse"><ref bean="father"/></property>
|
||||
<property name="touchy"><value/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="roderick" parent="rod">
|
||||
<property name="name"><value>Roderick<!-- a comment --></value></property>
|
||||
<!-- Should inherit age -->
|
||||
</bean>
|
||||
|
||||
<bean id="kerry" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>Ker<!-- a comment -->ry</value></property>
|
||||
<property name="age"><value>34</value></property>
|
||||
<property name="spouse"><ref local="rod"/></property>
|
||||
<property name="touchy"><value></value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="kathy" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>Kathy</value></property>
|
||||
<property name="age"><value>28</value></property>
|
||||
<property name="spouse"><ref bean="father"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="typeMismatch" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>typeMismatch</value></property>
|
||||
<property name="age"><value>34x</value></property>
|
||||
<property name="spouse"><ref local="rod"/></property>
|
||||
</bean>
|
||||
|
||||
<!-- Test of lifecycle callbacks -->
|
||||
<bean id="mustBeInitialized" class="org.springframework.beans.factory.MustBeInitialized"/>
|
||||
|
||||
<bean id="lifecycle" class="org.springframework.beans.factory.LifecycleBean"
|
||||
init-method="declaredInitMethod">
|
||||
<property name="initMethodDeclared"><value>true</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="protectedLifecycle" class="org.springframework.beans.factory.xml.ProtectedLifecycleBean"
|
||||
init-method="declaredInitMethod">
|
||||
<property name="initMethodDeclared"><value>true</value></property>
|
||||
</bean>
|
||||
|
||||
<!-- Factory beans are automatically treated differently -->
|
||||
<bean id="singletonFactory" class="org.springframework.beans.factory.DummyFactory">
|
||||
</bean>
|
||||
|
||||
<bean id="prototypeFactory" class="org.springframework.beans.factory.DummyFactory">
|
||||
<property name="singleton"><value>false</value></property>
|
||||
</bean>
|
||||
|
||||
<!-- Check that the circular reference resolution mechanism doesn't break
|
||||
repeated references to the same FactoryBean -->
|
||||
<bean id="factoryReferencer" class="org.springframework.beans.factory.xml.DummyReferencer">
|
||||
<property name="testBean1"><ref bean="singletonFactory"/></property>
|
||||
<property name="testBean2"><ref local="singletonFactory"/></property>
|
||||
<property name="dummyFactory"><ref bean="&singletonFactory"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="factoryReferencerWithConstructor" class="org.springframework.beans.factory.xml.DummyReferencer">
|
||||
<constructor-arg><ref bean="&singletonFactory"/></constructor-arg>
|
||||
<property name="testBean1"><ref bean="singletonFactory"/></property>
|
||||
<property name="testBean2"><ref local="singletonFactory"/></property>
|
||||
</bean>
|
||||
|
||||
<!-- Check that the circular reference resolution mechanism doesn't break
|
||||
prototype instantiation -->
|
||||
<bean id="prototypeReferencer" class="org.springframework.beans.factory.xml.DummyReferencer" scope="prototype">
|
||||
<property name="testBean1"><ref local="kathy"/></property>
|
||||
<property name="testBean2"><ref bean="kathy"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="listenerVeto" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>listenerVeto</value></property>
|
||||
<property name="age"><value>66</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="validEmpty" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="commentsInValue" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>this is<!-- don't mind me --> a <![CDATA[<!--comment-->]]></value></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,184 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||
|
||||
<util:constant id="min" static-field="
|
||||
java.lang.Integer.
|
||||
MIN_VALUE
|
||||
"/>
|
||||
|
||||
<util:constant static-field="java.lang.Integer.MAX_VALUE"/>
|
||||
|
||||
<util:property-path id="name" path="
|
||||
configuredBean.
|
||||
name
|
||||
"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name">
|
||||
<util:property-path path="configuredBean.name"/>
|
||||
</property>
|
||||
<property name="someProperties">
|
||||
<util:properties location="classpath:/org/springframework/beans/factory/config/util.properties"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="constructedTestBean" class="org.springframework.beans.TestBean">
|
||||
<constructor-arg index="0">
|
||||
<util:property-path path="configuredBean.name"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="configuredBean" class="org.springframework.beans.TestBean">
|
||||
<property name="name" value="Rob Harrop"/>
|
||||
</bean>
|
||||
|
||||
<util:map id="simpleMap">
|
||||
<entry key="foo" value="bar"/>
|
||||
</util:map>
|
||||
|
||||
<util:map id="scopedMap" scope="prototype">
|
||||
<description>My scoped Map</description>
|
||||
<entry key="foo" value="bar"/>
|
||||
</util:map>
|
||||
|
||||
<util:map id="mapWithRef" map-class="java.util.TreeMap">
|
||||
<entry key="bean" value-ref="testBean"/>
|
||||
</util:map>
|
||||
|
||||
<util:list id="simpleList">
|
||||
<value>Rob Harrop</value>
|
||||
</util:list>
|
||||
|
||||
<util:list id="scopedList" scope="prototype">
|
||||
<description>My scoped List</description>
|
||||
<value>Rob Harrop</value>
|
||||
</util:list>
|
||||
|
||||
<util:set id="simpleSet">
|
||||
<value>Rob Harrop</value>
|
||||
</util:set>
|
||||
|
||||
<util:set id="scopedSet" scope="prototype">
|
||||
<description>My scoped Set</description>
|
||||
<value>Rob Harrop</value>
|
||||
</util:set>
|
||||
|
||||
<bean id="nestedCollectionsBean" class="org.springframework.beans.TestBean">
|
||||
<property name="someList">
|
||||
<util:list>
|
||||
<value>foo</value>
|
||||
</util:list>
|
||||
</property>
|
||||
<property name="someSet">
|
||||
<util:set>
|
||||
<value>bar</value>
|
||||
</util:set>
|
||||
</property>
|
||||
<property name="someMap">
|
||||
<util:map>
|
||||
<entry key="foo">
|
||||
<util:set>
|
||||
<value>bar</value>
|
||||
</util:set>
|
||||
</entry>
|
||||
</util:map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="nestedCustomTagBean" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="someList">
|
||||
<list>
|
||||
<util:constant static-field="java.lang.Integer.MIN_VALUE"/>
|
||||
</list>
|
||||
</property>
|
||||
<property name="someSet">
|
||||
<set>
|
||||
<util:constant static-field="java.lang.Integer.MIN_VALUE"/>
|
||||
</set>
|
||||
</property>
|
||||
<property name="someMap">
|
||||
<map>
|
||||
<entry>
|
||||
<key><value>min</value></key>
|
||||
<util:constant static-field="java.lang.Integer.MIN_VALUE"/>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="circularCollectionsBean" class="org.springframework.beans.TestBean">
|
||||
<property name="someList">
|
||||
<util:list>
|
||||
<ref bean="circularCollectionsBean"/>
|
||||
</util:list>
|
||||
</property>
|
||||
<property name="someSet">
|
||||
<util:set>
|
||||
<ref bean="circularCollectionsBean"/>
|
||||
</util:set>
|
||||
</property>
|
||||
<property name="someMap">
|
||||
<util:map>
|
||||
<entry key="foo" value-ref="circularCollectionsBean"/>
|
||||
</util:map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<util:list id="circularList">
|
||||
<ref bean="circularCollectionBeansBean"/>
|
||||
</util:list>
|
||||
|
||||
<util:set id="circularSet">
|
||||
<ref bean="circularCollectionBeansBean"/>
|
||||
</util:set>
|
||||
|
||||
<util:map id="circularMap">
|
||||
<entry key="foo" value-ref="circularCollectionBeansBean"/>
|
||||
</util:map>
|
||||
|
||||
<bean id="circularCollectionBeansBean" class="org.springframework.beans.TestBean">
|
||||
<property name="someList" ref="circularList"/>
|
||||
<property name="someSet" ref="circularSet"/>
|
||||
<property name="someMap" ref="circularMap"/>
|
||||
</bean>
|
||||
|
||||
<util:properties id="myProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties"/>
|
||||
|
||||
<util:properties id="myScopedProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties" scope="prototype"/>
|
||||
|
||||
<util:properties id="myLocalProperties">
|
||||
<prop key="foo2">bar2</prop>
|
||||
</util:properties>
|
||||
|
||||
<util:properties id="myMergedProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties">
|
||||
<prop key="foo2">bar2</prop>
|
||||
</util:properties>
|
||||
|
||||
<util:properties id="defaultLocalOverrideProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties">
|
||||
<prop key="foo">local</prop>
|
||||
<prop key="foo2">local2</prop>
|
||||
</util:properties>
|
||||
|
||||
<util:properties id="trueLocalOverrideProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties"
|
||||
local-override="true">
|
||||
<prop key="foo">local</prop>
|
||||
<prop key="foo2">local2</prop>
|
||||
</util:properties>
|
||||
|
||||
<util:properties id="falseLocalOverrideProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties"
|
||||
local-override="false">
|
||||
<prop key="foo">local</prop>
|
||||
<prop key="foo2">local2</prop>
|
||||
</util:properties>
|
||||
|
||||
</beans>
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
This is a top level block comment
|
||||
-->
|
||||
<!-- here is a line comment -->
|
||||
<!-- trying --> <!-- to trick --> <!--
|
||||
the parser now --> <!-- <beans>
|
||||
-->
|
||||
<!-- more trickery--> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"><!-- some nasty stuff -->
|
||||
|
||||
<beans>
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
</beans>
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
This is a top level block comment
|
||||
-->
|
||||
<!-- here is a line comment -->
|
||||
<!-- trying --> <!-- to trick --> <!--
|
||||
the parser now --> <!-- <beans>
|
||||
-->
|
||||
<!-- more trickery--><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.0.xsd"><!-- end -->
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
</beans>
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<spring:beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:spring="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<spring:bean id="testBean1" class="org.springframework.beans.TestBean">
|
||||
<spring:meta key="foo" value="bar"/>
|
||||
</spring:bean>
|
||||
|
||||
<spring:bean id="testBean2" class="org.springframework.beans.TestBean" parent="testBean1">
|
||||
<spring:meta key="abc" value="123"/>
|
||||
</spring:bean>
|
||||
|
||||
<spring:bean id="testBean3" class="org.springframework.beans.TestBean">
|
||||
<spring:property name="name" value="Rob">
|
||||
<spring:meta key="surname" value="Harrop"/>
|
||||
</spring:property>
|
||||
</spring:bean>
|
||||
|
||||
</spring:beans>
|
||||
Loading…
Reference in New Issue