Nate, somehow I posted back to you privately instead of the thread. I'm
including your response here in case someone else missed the tidbit about
how to make a module private.
Thank you again - Richard
---------- Forwarded message ----------
From: Nate Bauernfeind
Date: Fri, Mar 21, 2014 at 9:58 AM
Subject: Re: Private message regarding: Injecting String properties into
multiple modules
To: Richard Mixon
You're welcome; I'm glad that I helped!
A module is either private or public based on the class that you extend.
Typically your module will either extend AbstractModule or PrivateModule,
and the latter is private.
Happy Guicing ;),
Nate
On Thu, Mar 20, 2014 at 6:37 PM, Richard Mixon wrote:
> Nate,
>
> Thank you much - that did the trick. In my case I just created a class
> that extends AbstractModule. Then in my AppListener included it like this:
> Injector inj = Guice.createInjector(hbPubMod,
> hbShWebMod,servletMod,hbMBMod);
>
> I found in the Guice doc where it says private modules have to explicitly
> expose any configuration they want to be shared. I'm a bit curious though
> - how do you make a module private?
>
> Thanks again - Richard
>
> On Tuesday, March 18, 2014 1:56:05 PM UTC-7, Nate Bauernfeind wrote:
>>
>> Can you move the property-file loading into a separate public module
>> (named something like ConfigurationModule)? It seems like the problem is
>> that your loading them in a private module and then not exposing any of the
>> properties. Or I could be missing the bigger picture.
>>
>>
>> On Tue, Mar 18, 2014 at 1:52 PM, Richard Mixon wrote:
>>
>>> We have a web application configured by extending
>>> GuiceServletContextListener. In addition to configuring the normal
>>> ServletModule, we also have two private modules that extend MyBatisModule
>>> and ShiroWebModule.
>>>
>>> In the ShiroWebModule we load a properties file and bind the properties
>>> like this:
>>>
>>> ...
>>> @Override
>>> public void configure() {
>>> super.configure();
>>> loadLDAPProperties(binder());
>>> }
>>> ...
>>> @SuppressWarnings("unchecked")
>>> protected void configureShiroWeb() {
>>> try {
>>> this.
>>> bindRealm().to(InjectableCasRealm.class);
>>> ShiroWebModule.guiceFilterModule();
>>> } catch (Exception e) {
>>> addError(e);
>>> }
>>>
>>> // Key<RolesAuthorizationFilter> rolesFilter =
>>> Key.get(RolesAuthorizationFilter.class);
>>> expose(RolesAuthorizationFilter.class);
>>>
>>> addFilterChain("/xyz.jsp", ANON);
>>> ...
>>> Key<InjectableCasFilter> casFilter =
>>> Key.get(InjectableCasFilter.class);
>>> addFilterChain("/shiro-cas", casFilter);
>>> expose(InjectableCasFilter.class);
>>> }
>>> ...
>>> private void loadLDAPProperties(Binder binder) {
>>> props = new Properties();
>>> try {
>>>
>>> props.load(getClass().getClassLoader().getResourceAsStream(props_filename));
>>> Names.bindProperties(binder, props);
>>> } catch (IOException e) {
>>> binder.addError(e);
>>> }
>>> }
>>>
>>> We are then able to inject those properties into the InjectableCasRealm
>>> class like this:
>>> public class InjectableCasRealm extends CasRealm {
>>> private String casServerUrl;
>>>
>>> @Inject
>>> public void setCasServerUrl(@Named("injCasRealm.casServerUrl")
>>> String casServerUrl) {
>>> this.casServerUrl = casServerUrl;
>>> }
>>> ...
>>>
>>> We would like to inject some of the properties into our servlet's
>>> configured using the ServletModule but we keep getting this error:
>>> SEVERE: Exception starting filter GuiceFilter
>>> com.google.inject.ConfigurationException: Guice configuration errors:
>>>
>>> 1) Unable to create binding for java.lang.String annotated with
>>> @com.google.inject.name.Named(value=heartbeat.logoutUrl). It was already
>>> configured on one or more child injectors or private modules
>>> bound at
>>> com.trumpetinc.environment.HBShiroWebModule.loadLDAPProperties(HBShiroWebModule.java:79)
>>> If it was in a PrivateModule, did you forget to expose the binding?
>>> while locating java.lang.String annotated with
>>> @com.google.inject.name.Named(value=heartbeat.logoutUrl)
>>> for parameter 0 at
>>> com.trumpetinc.heartbeat.HandleCheckHeartbeatRequest.setHeartbeatLogoutUrl(HandleCheckHeartbeatRequest.java:89)
>>> at
>>> com.trumpetinc.heartbeat.HandleCheckHeartbeatRequest.setHeartbeatLogoutUrl(HandleCheckHeartbeatRequest.java:89)
>>> while locating com.trumpetinc.heartbeat.HandleCheckHeartbeatRequest
>>>
>>> 1 error
>>>
>>> We can create a separate properties file with just the properties we
>>> need and load/bind them in the ServletModule extension - but we though
>>> there might be a better way.
>>>
>>> How can we inject the properties loaded in the ShiroWebModule extension
>>> so they can be used by our servlets?
>>>
>>> Thank you - Richard
>>>
>>> --
>>>
>>>
>>
--
On Tuesday, March 18, 2014 11:52:15 AM UTC-7, Richard Mixon wrote:
>
> We have a web application configured by extending
> GuiceServletContextListener. In addition to configuring the normal
> ServletModule, we also have two private modules that extend MyBatisModule
> and ShiroWebModule.
>
> In the ShiroWebModule we load a properties file and bind the properties
> like this:
>
> ...
> @Override
> public void configure() {
> super.configure();
> loadLDAPProperties(binder());
> }
> ...
> @SuppressWarnings("unchecked")
> protected void configureShiroWeb() {
> try {
> this.
> bindRealm().to(InjectableCasRealm.class);
> ShiroWebModule.guiceFilterModule();
> } catch (Exception e) {
> addError(e);
> }
>
> // Key<RolesAuthorizationFilter> rolesFilter =
> Key.get(RolesAuthorizationFilter.class);
> expose(RolesAuthorizationFilter.class);
>
> addFilterChain("/xyz.jsp", ANON);
> ...
> Key<InjectableCasFilter> casFilter =
> Key.get(InjectableCasFilter.class);
> addFilterChain("/shiro-cas", casFilter);
> expose(InjectableCasFilter.class);
> }
> ...
> private void loadLDAPProperties(Binder binder) {
> props = new Properties();
> try {
>
> props.load(getClass().getClassLoader().getResourceAsStream(props_filename));
> Names.bindProperties(binder, props);
> } catch (IOException e) {
> binder.addError(e);
> }
> }
>
> We are then able to inject those properties into the InjectableCasRealm
> class like this:
> public class InjectableCasRealm extends CasRealm {
> private String casServerUrl;
>
> @Inject
> public void setCasServerUrl(@Named("injCasRealm.casServerUrl") String
> casServerUrl) {
> this.casServerUrl = casServerUrl;
> }
> ...
>
> We would like to inject some of the properties into our servlet's
> configured using the ServletModule but we keep getting this error:
> SEVERE: Exception starting filter GuiceFilter
> com.google.inject.ConfigurationException: Guice configuration errors:
>
> 1) Unable to create binding for java.lang.String annotated with
> @com.google.inject.name.Named(value=heartbeat.logoutUrl). It was already
> configured on one or more child injectors or private modules
> bound at
> com.trumpetinc.environment.HBShiroWebModule.loadLDAPProperties(HBShiroWebModule.java:79)
> If it was in a PrivateModule, did you forget to expose the binding?
> while locating java.lang.String annotated with
> @com.google.inject.name.Named(value=heartbeat.logoutUrl)
> for parameter 0 at
> com.trumpetinc.heartbeat.HandleCheckHeartbeatRequest.setHeartbeatLogoutUrl(HandleCheckHeartbeatRequest.java:89)
> at
> com.trumpetinc.heartbeat.HandleCheckHeartbeatRequest.setHeartbeatLogoutUrl(HandleCheckHeartbeatRequest.java:89)
> while locating com.trumpetinc.heartbeat.HandleCheckHeartbeatRequest
>
> 1 error
>
> We can create a separate properties file with just the properties we need
> and load/bind them in the ServletModule extension - but we though there
> might be a better way.
>
> How can we inject the properties loaded in the ShiroWebModule extension
> so they can be used by our servlets?
>
> Thank you - Richard
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.