You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Belfer-Shevett <db...@homeport.org> on 2008/06/11 15:59:43 UTC
ApplicationAware not triggering setApplication? Or, how best to
reference a Connection pool?
Hi folks - i'm trying to write an interceptor in struts2 that has access
to the ApplicationMap in the application context.
My understanding is that the webwork API for ApplicationAware means that
the interceptor will have it's setApplication(Map applicationData);
triggered when the interceptor is run, thereby giving me access to the
applicationcontext.
Problem is, it isn't :)
Here's the relevant parts...
public class DBInterceptor extends AbstractInterceptor implements
ApplicationAware {
...
@Override
public void setApplication(Map arg0) {
logger.info("Receiving applicationMap...");
this.applicationMap = arg0;
}
That logger is never triggered, 'applicationMap' is always null.
My struts.xml is:
<interceptors>
<interceptor name="dbsetup"
class="com.stonekeep.congo.interceptors.DBInterceptor" />
<interceptor-stack name="mystack">
<interceptor-ref name="dbsetup" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
(The goal here is to store a c3p0 connection pool object in the
application context, so that I can get a connection from it on every hit
- I assume this is the proper way to do this?)
Thanks, any help would be appreciated...
-dbs
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ApplicationAware not triggering setApplication? Or, how best
to reference a Connection pool?
Posted by Dave Belfer-Shevett <db...@homeport.org>.
Lukasz Lenart wrote:
>> My understanding is that the webwork API for ApplicationAware means that the
>> interceptor will have it's setApplication(Map applicationData); triggered
>> when the interceptor is run, thereby giving me access to the
>> applicationcontext.
>
> ApplicationAware should be used with Actions not with interceptors, to
> access application just use
>
> public String intercept(ActionInvocation invocation) {
> Map appScope = invocation.getInvocationContext().getApplication();
> }
That's done it, thank you very much. I was really stymied.
-dbs
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ApplicationAware not triggering setApplication? Or, how best to reference a Connection pool?
Posted by Lukasz Lenart <lu...@googlemail.com>.
> My understanding is that the webwork API for ApplicationAware means that the
> interceptor will have it's setApplication(Map applicationData); triggered
> when the interceptor is run, thereby giving me access to the
> applicationcontext.
ApplicationAware should be used with Actions not with interceptors, to
access application just use
public String intercept(ActionInvocation invocation) {
Map appScope = invocation.getInvocationContext().getApplication();
}
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ApplicationAware not triggering setApplication? Or, how best
to reference a Connection pool?
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Dave Belfer-Shevett wrote:
> Hi folks - i'm trying to write an interceptor in struts2 that has
> access to the ApplicationMap in the application context.
>
> My understanding is that the webwork API for ApplicationAware means
> that the interceptor will have it's setApplication(Map
> applicationData); triggered when the interceptor is run, thereby
> giving me access to the applicationcontext.
>
The ApplicationAware interface only applies to actions. It's actually a
feature of the ServletConfigInterceptor. That interceptor inspects the
target action for the interface and injects the Map if present.
XWork's dependency injection uses the @Inject annotation on properties
and constructions. It can inject beans it knows of, however the
application context is not one of them.
The simplest way to access the application context in your interceptor
is via the ActionInvocation argument:
ie. Map applicationContext =
actionInvocation.getIncovationContext().getApplication();
You can also inject beans directly into you interceptor via spring or
guice if you're using one of those DI frameworks.
Hope that helps,
Jeromy Evans
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org