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 <[email protected]> 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.
>

-- 
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.

Reply via email to