-
Notifications
You must be signed in to change notification settings - Fork 38k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotation post-processors clear old InjectionMetadata registrations …
…on refresh Issue: SPR-12526
- Loading branch information
Showing
6 changed files
with
217 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
...ext/src/test/java/org/springframework/context/annotation/configuration/Spr12526Tests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Copyright 2002-2014 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.context.annotation.configuration; | ||
|
||
import javax.annotation.Resource; | ||
|
||
import org.junit.Test; | ||
|
||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Scope; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.springframework.beans.factory.config.BeanDefinition.*; | ||
|
||
/** | ||
* @author Marcin Piela | ||
* @author Juergen Hoeller | ||
*/ | ||
public class Spr12526Tests { | ||
|
||
@Test | ||
public void testInjection() { | ||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TestContext.class); | ||
CustomCondition condition = ctx.getBean(CustomCondition.class); | ||
|
||
condition.setCondition(true); | ||
FirstService firstService = (FirstService) ctx.getBean(Service.class); | ||
assertNotNull("FirstService.dependency is null", firstService.getDependency()); | ||
|
||
condition.setCondition(false); | ||
SecondService secondService = (SecondService) ctx.getBean(Service.class); | ||
assertNotNull("SecondService.dependency is null", secondService.getDependency()); | ||
} | ||
|
||
|
||
@Configuration | ||
public static class TestContext { | ||
|
||
@Bean | ||
@Scope(SCOPE_SINGLETON) | ||
public CustomCondition condition() { | ||
return new CustomCondition(); | ||
} | ||
|
||
|
||
@Bean | ||
@Scope(SCOPE_PROTOTYPE) | ||
public Service service(CustomCondition condition) { | ||
return (condition.check() ? new FirstService() : new SecondService()); | ||
} | ||
|
||
@Bean | ||
public DependencyOne dependencyOne() { | ||
return new DependencyOne(); | ||
} | ||
|
||
|
||
@Bean | ||
public DependencyTwo dependencyTwo() { | ||
return new DependencyTwo(); | ||
} | ||
} | ||
|
||
|
||
public static class CustomCondition { | ||
|
||
private boolean condition; | ||
|
||
public boolean check() { | ||
return condition; | ||
} | ||
|
||
public void setCondition(boolean value) { | ||
this.condition = value; | ||
} | ||
} | ||
|
||
|
||
public interface Service { | ||
|
||
void doStuff(); | ||
} | ||
|
||
|
||
public static class FirstService implements Service { | ||
|
||
private DependencyOne dependency; | ||
|
||
|
||
@Override | ||
public void doStuff() { | ||
if (dependency == null) { | ||
throw new IllegalStateException("FirstService: dependency is null"); | ||
} | ||
} | ||
|
||
@Resource(name = "dependencyOne") | ||
public void setDependency(DependencyOne dependency) { | ||
this.dependency = dependency; | ||
} | ||
|
||
|
||
public DependencyOne getDependency() { | ||
return dependency; | ||
} | ||
} | ||
|
||
|
||
public static class SecondService implements Service { | ||
|
||
private DependencyTwo dependency; | ||
|
||
@Override | ||
public void doStuff() { | ||
if (dependency == null) { | ||
throw new IllegalStateException("SecondService: dependency is null"); | ||
} | ||
} | ||
|
||
@Resource(name = "dependencyTwo") | ||
public void setDependency(DependencyTwo dependency) { | ||
this.dependency = dependency; | ||
} | ||
|
||
|
||
public DependencyTwo getDependency() { | ||
return dependency; | ||
} | ||
} | ||
|
||
|
||
public static class DependencyOne { | ||
} | ||
|
||
|
||
public static class DependencyTwo { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters