-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure *Aware contracts can be satisfied in ModuleRegistryConfiguration
If the BeanFactoryProvider is used there is a partially refreshed ApplicationContext floating around. It works better if it is able to inject Environment etc. via the Aware interfaces into early beans like post processors.
- Loading branch information
Dave Syer
committed
Jan 10, 2019
1 parent
af2497c
commit fd83548
Showing
3 changed files
with
152 additions
and
44 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
95 changes: 95 additions & 0 deletions
95
src/test/java/org/springframework/guice/module/SpringModuleWrappedTests.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,95 @@ | ||
/* | ||
* Copyright 2016-2017 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.guice.module; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
|
||
import org.junit.Test; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.guice.annotation.EnableGuiceModules; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class SpringModuleWrappedTests { | ||
|
||
@Test | ||
public void testDependenciesFromWrappedModule() { | ||
Injector injector = Guice.createInjector(new SpringModule( | ||
BeanFactoryProvider.from(TestConfig.class, ModuleProviderConfig.class))); | ||
assertNotNull(injector.getInstance(Baz.class)); | ||
} | ||
|
||
@Configuration | ||
public static class TestConfig { | ||
@Bean | ||
public Baz baz(Service service) { | ||
return new Baz(service); | ||
} | ||
|
||
} | ||
|
||
interface Service { | ||
} | ||
|
||
protected static class MyService implements Service { | ||
} | ||
|
||
public static class Foo { | ||
|
||
@Inject | ||
public Foo(@Named("service") Service service) { | ||
service.toString(); | ||
} | ||
} | ||
|
||
public static class Baz { | ||
|
||
@Inject | ||
public Baz(Service service) { | ||
} | ||
|
||
} | ||
|
||
@Configuration | ||
@EnableGuiceModules | ||
protected static class ModuleProviderConfig { | ||
|
||
@Bean | ||
public ProviderModule module() { | ||
return new ProviderModule(); | ||
} | ||
|
||
@Bean | ||
public Foo service(Service service) { | ||
return new Foo(service); | ||
} | ||
|
||
} | ||
|
||
protected static class ProviderModule extends AbstractModule { | ||
|
||
@Override | ||
protected void configure() { | ||
bind(Service.class).toProvider(() -> new MyService()); | ||
} | ||
|
||
} | ||
|
||
} |