You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to implement a fully automatic configuration feature similar to Spring Boot based on the Guice framework. The static method, ‘Run’, is the application main entry point, similar to Spring Boot’s ‘SpringApplication.run’ method. This method mainly does two things: it scans all classes with the ‘@service’ annotation under a specific package, and it configures these classes in an ‘AbstractModule’. During the implementation process, I encountered a problem: I cannot bind the interface information obtained through reflection to the corresponding implementation class. Can you provide me with some guidance? My implementation code:
`public static Injector run(Class<?> mainClass, String[] args) {
String[] packages = getScanPackages(mainClass);
final Set<Class<?>> clazzSet = new HashSet<>();
for (String pkg : packages) {
clazzSet.addAll(list(pkg));
}
if (CollectionUtils.isEmpty(clazzSet)) {
return Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
super.configure();
}
});
}
return Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
for (Class<?> clz : clazzSet) {
Class<?>[] interfaces = clz.getInterfaces();
if (interfaces.length == 0) {
bind(clz).in(Scopes.SINGLETON);
} else if (interfaces.length > 0) {
bind(interfaces[0]).to(clz).in(Scopes.SINGLETON);
}
}
}
});
}`
The text was updated successfully, but these errors were encountered:
I want to implement a fully automatic configuration feature similar to Spring Boot based on the Guice framework. The static method, ‘Run’, is the application main entry point, similar to Spring Boot’s ‘SpringApplication.run’ method. This method mainly does two things: it scans all classes with the ‘@service’ annotation under a specific package, and it configures these classes in an ‘AbstractModule’. During the implementation process, I encountered a problem: I cannot bind the interface information obtained through reflection to the corresponding implementation class. Can you provide me with some guidance? My implementation code:
`public static Injector run(Class<?> mainClass, String[] args) {
String[] packages = getScanPackages(mainClass);
The text was updated successfully, but these errors were encountered: