Milimber
Milimber

Reputation: 31

Access Hibernate with out apache Tapestry injection

Im trying to access a hibernate entity/database from a shiro AuthorizingRealm extending class. Since the tapestry IOC does not inject outside Pages / Components, how do I access the Hibernate Session so I can access the database?

Upvotes: 0

Views: 108

Answers (3)

user3179728
user3179728

Reputation:

Try add this to your AppModule (MongoDB example):

@Contribute(WebSecurityManager.class)
public static void addRealms(Configuration<Realm> configuration, @Autobuild MongoRealm realm)
{
    configuration.add(realm);
}

and provide also your AuthorizingRealm:

public class MongoRealm extends AuthorizingRealm
{
   @Inject
   private SomeDAO someDAO;
   ...
}

Upvotes: 2

lance-java
lance-java

Reputation: 28099

Tapestry IOC can only @Inject into a service that it has created itself. If you have constructed the AuthorizingRealm using new then the instance is not under IOC control and won't be injected.

Either @Autobuild the AuthorizingRealm instance or declare it as a service in your IOC module.

Upvotes: 0

Howard M. Lewis Ship
Howard M. Lewis Ship

Reputation: 549

If you can get access to the Tapestry Registry (it is stored in the Servlet Context, for example), then you can gain access to the necessary services inside Tapestry and ultimately to the Hibernate Session.

Upvotes: 0

Related Questions