14 changed files with 420 additions and 21 deletions
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
/* |
||||
* Copyright 2002-present 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 |
||||
* |
||||
* https://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.context; |
||||
|
||||
import org.springframework.beans.factory.BeanRegistrar; |
||||
import org.springframework.beans.factory.BeanRegistry; |
||||
import org.springframework.core.ParameterizedTypeReference; |
||||
import org.springframework.core.env.Environment; |
||||
|
||||
/** |
||||
* A variant of {@link BeanRegistrar} which aims to be invoked |
||||
* at the end of the bean registration phase, coming after regular |
||||
* bean definition reading and configuration class processing. |
||||
* |
||||
* <p>This allows for seeing all user-registered beans, potentially |
||||
* reacting to their presence. The {@code containsBean} methods on |
||||
* {@link BeanRegistry} will provide reliable answers, independent |
||||
* of the order of user bean registration versus {@code BeanRegistrar} |
||||
* import/registration. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 7.1 |
||||
* @see #register(BeanRegistry, Environment) |
||||
* @see BeanRegistry#containsBean(String) |
||||
* @see BeanRegistry#containsBean(Class) |
||||
* @see BeanRegistry#containsBean(ParameterizedTypeReference) |
||||
* @see org.springframework.context.support.GenericApplicationContext#register( BeanRegistrar...) |
||||
* @see org.springframework.context.annotation.Import |
||||
*/ |
||||
public interface DeferredBeanRegistrar extends BeanRegistrar { |
||||
|
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* |
||||
* Copyright 2002-present 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 |
||||
* |
||||
* https://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.context.testfixture.beans.factory; |
||||
|
||||
import org.springframework.beans.factory.BeanRegistry; |
||||
import org.springframework.beans.testfixture.beans.TestBean; |
||||
import org.springframework.context.DeferredBeanRegistrar; |
||||
import org.springframework.core.ParameterizedTypeReference; |
||||
import org.springframework.core.env.Environment; |
||||
|
||||
public class MyDeferredBeanRegistrar implements DeferredBeanRegistrar { |
||||
|
||||
@Override |
||||
public void register(BeanRegistry registry, Environment env) { |
||||
if (registry.containsBean("testBean") && |
||||
registry.containsBean(TestBean.class) && |
||||
registry.containsBean(new ParameterizedTypeReference<Comparable<Object>>() { |
||||
})) { |
||||
registry.registerBean("myTestBean", TestBean.class); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright 2002-present 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 |
||||
* |
||||
* https://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.context.testfixture.beans.factory; |
||||
|
||||
import org.springframework.beans.factory.BeanRegistrar; |
||||
import org.springframework.beans.factory.BeanRegistry; |
||||
import org.springframework.beans.testfixture.beans.TestBean; |
||||
import org.springframework.core.ParameterizedTypeReference; |
||||
import org.springframework.core.env.Environment; |
||||
|
||||
public class MyRegularBeanRegistrar implements BeanRegistrar { |
||||
|
||||
@Override |
||||
public void register(BeanRegistry registry, Environment env) { |
||||
if (registry.containsBean("testBean") && |
||||
registry.containsBean(TestBean.class) && |
||||
registry.containsBean(new ParameterizedTypeReference<Comparable<Object>>() { |
||||
})) { |
||||
registry.registerBean("myTestBean", TestBean.class); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
/* |
||||
* Copyright 2002-present 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 |
||||
* |
||||
* https://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.context.testfixture.context.annotation.registrar; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.Import; |
||||
import org.springframework.context.testfixture.beans.factory.MyDeferredBeanRegistrar; |
||||
|
||||
@Configuration |
||||
@Import(MyDeferredBeanRegistrar.class) |
||||
public class MyDeferredBeanRegistrarConfiguration { |
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
/* |
||||
* Copyright 2002-present 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 |
||||
* |
||||
* https://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.context.testfixture.context.annotation.registrar; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.Import; |
||||
import org.springframework.context.testfixture.beans.factory.MyRegularBeanRegistrar; |
||||
|
||||
@Configuration |
||||
@Import(MyRegularBeanRegistrar.class) |
||||
public class MyRegularBeanRegistrarConfiguration { |
||||
} |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/* |
||||
* Copyright 2002-present 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 |
||||
* |
||||
* https://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.context.testfixture.context.annotation.registrar; |
||||
|
||||
import org.springframework.beans.testfixture.beans.TestBean; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
@Configuration |
||||
public class TestBeanConfiguration { |
||||
|
||||
@Bean |
||||
public TestBean testBean() { |
||||
return new TestBean(); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue