I get the error
org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
java.lang.SecurityException: No security context bound to the current thread
using a scheduled task on the core module to execute a task once at application start:
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="app_OlapService" method="initialize" fixed-rate="9223372036854775807"/>
</task:scheduled-tasks>
I've tried both the @Authenticated annotation and authentication.begin() on injected Authentication instance.
It looks like an error triggered by the scheduling alone, I'm also having the same error with an empty method body.
I'm also open to alternative approaches, considering that I need to use a transaction and @PostConstruct AppContext.Listener don't allow me to.
Perhaps you are invoking a method of a service. Such invocations are intercepted and checked for the presence of a valid user session, so it should already exist at the moment of invocation. It works when a service is invoked from a client or from an already authenticated middleware code.
In your case, I would recommend extracting logic from service to a managed bean and invoke it both from service and scheduler.
As for AppContext.Listener
, in the applicationStarted()
method you can do whatever you want including programmatic transaction management.