Adil Quraish
2018-06-18 15:19:46 UTC
I am trying to get Guice to work in a web application deployed on JBoss EAP
6.4 When I try to step through the Guice code, I notice that the binding is
happening. However, when I try to inject the bound object, I always get
null. The following are the code changes I have done to enable Guice -
1) *web.xml*
<listener>
<listener-class>com.univeris.guice.GuiceConfig</listener-class>
</listener>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2) *GuiceConfig*
@Singleton
public class GuiceConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
Injector injector = Guice.createInjector(
new ServletModule() {
@Override
protected void configureServlets() {
serve("/uif/*").with(UIFInitializeServlet.class);
serve("/upm/*").with(IDPServlet.class, ImmutableMap.of("instance-name","upm"));
serve("/uiw/*").with(IDPServlet.class, ImmutableMap.of("instance-name","uiw"));
}
},
new MainModule()
);
return injector;
}
}
3) *MainModule*
public class MainModule extends AbstractModule {
@Override
protected void configure() {
install(new BankAccountModule());
install(new CoreModule());
}
}
4) *BankAccountModule*
public class BankAccountModule extends AbstractModule {
@Override
protected void configure() {
bind(BankAccountProvider.class).toProvider(BankAccountGuiceProvider.class);
bind(BankAccountService.class).toProvider(BankAccountServiceProvider.class);
}
}
5) *BankAccountGuiceProvider*
public class BankAccountGuiceProvider implements Provider<BankAccountProvider> {
@Override
public BankAccountProvider get() {
return ProviderLocator.locateProvider(BankAccountProvider.class);
}
}
6) *BankAccountServiceUVS*
@Stateless
@Interceptors(ServiceInterceptor.class)
public class BankAccountServiceUVS implements BankAccountService {
@Inject
private BankAccountProvider _bankAccountProvider;
@Override
public BankAccountCollection getAllBankAccounts(final Integer entityId, final String entityType) {
BankAccountCollection retVal = _bankAccountProvider.getAllBankAccounts(entityId,
return PojoHelper.cloneObject(retVal);
}
}
The *_bankAccountProvider* is always injected as null. I have been pouring
through several forums for several days to no avail. Can someone point out
what I am missing?
6.4 When I try to step through the Guice code, I notice that the binding is
happening. However, when I try to inject the bound object, I always get
null. The following are the code changes I have done to enable Guice -
1) *web.xml*
<listener>
<listener-class>com.univeris.guice.GuiceConfig</listener-class>
</listener>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2) *GuiceConfig*
@Singleton
public class GuiceConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
Injector injector = Guice.createInjector(
new ServletModule() {
@Override
protected void configureServlets() {
serve("/uif/*").with(UIFInitializeServlet.class);
serve("/upm/*").with(IDPServlet.class, ImmutableMap.of("instance-name","upm"));
serve("/uiw/*").with(IDPServlet.class, ImmutableMap.of("instance-name","uiw"));
}
},
new MainModule()
);
return injector;
}
}
3) *MainModule*
public class MainModule extends AbstractModule {
@Override
protected void configure() {
install(new BankAccountModule());
install(new CoreModule());
}
}
4) *BankAccountModule*
public class BankAccountModule extends AbstractModule {
@Override
protected void configure() {
bind(BankAccountProvider.class).toProvider(BankAccountGuiceProvider.class);
bind(BankAccountService.class).toProvider(BankAccountServiceProvider.class);
}
}
5) *BankAccountGuiceProvider*
public class BankAccountGuiceProvider implements Provider<BankAccountProvider> {
@Override
public BankAccountProvider get() {
return ProviderLocator.locateProvider(BankAccountProvider.class);
}
}
6) *BankAccountServiceUVS*
@Stateless
@Interceptors(ServiceInterceptor.class)
public class BankAccountServiceUVS implements BankAccountService {
@Inject
private BankAccountProvider _bankAccountProvider;
@Override
public BankAccountCollection getAllBankAccounts(final Integer entityId, final String entityType) {
BankAccountCollection retVal = _bankAccountProvider.getAllBankAccounts(entityId,
return PojoHelper.cloneObject(retVal);
}
}
The *_bankAccountProvider* is always injected as null. I have been pouring
through several forums for several days to no avail. Can someone point out
what I am missing?
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/674dcd19-115c-43b3-bf58-572193bb619b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/674dcd19-115c-43b3-bf58-572193bb619b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.