Add auto scan component and configuration for Guice
<dependencies>
<dependency>
<groupId>com.talanlabs</groupId>
<artifactId>guice-tools</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
By default add @Component
in bind class
@Component
public class MyExample {
...
}
And install scan module in guice module
install(new ComponentScanModule("com.example"));
Or change scan with @Singleton
install(new ComponentScanModule("com.example",Singleton.class));
By defualt add @Configuration
in install module
@Configuration
public class MyModule extends AbstractModule {
...
}
And install scan module in guice module
install(new ConfigurationScanModule("com.example"));
Guice.createInjector(new LoggerModuler(),...);
Inject field
@InjectLogger
Logger logger;
Inject method
@InjectLogger
void setLogger(Logger logger) {
}
Change name, default is class name
@InjectLogger("test")