Hi i'm trying to access to a Session Bean from Singleton Bean (org.springframework-version --> 3.1.2.RELEASE).
These are the listeners added in my web.xml
This is Session Bean declaration:
This is the Singleton Bean:
When the Session Bean method is called from Singleton Bean is thrown the following exception:
Why the AOP doesn't work??
Moreover in the same application i have the following bean that inject the same session bean and it works:
With this xml configuration:
These are the listeners added in my web.xml
Code:
<!-- Loads the Spring web application context -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Support the scoping of beans at the request, session, and global session levels (web-scoped beans), -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>Code:
<bean id="sessionProxy" class="com.xxxxxxxx.csp.list.SessionProxy" scope="session">
<aop:scoped-proxy />
</bean>This is the Singleton Bean:
Code:
import javax.jms.Message;
import javax.jms.MessageListener;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.xxxxxx.csp.list.SessionProxy;
public class RealtimeListener implements MessageListener {
private static Logger logger = Logger.getLogger(RealtimeListener.class);
@Autowired
private SessionProxy sessionProxy;
public SessionProxy getSessionProxy() {
return sessionProxy;
}
public void setSessionProxy(SessionProxy sessionProxy) {
this.sessionProxy = sessionProxy;
}
public void onMessage(Message message) {
try{
logger.info(this.getSessionProxy().getPippo());
}catch(Exception e ){
logger.error(e.getStackTrace());
}
}
}Code:
2013-05-23 14:01:28,711 ERROR [com.xxxxxx.csp.realtime.RealtimeListener] ERROR
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sessionProxy': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:342)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.getTarget(Cglib2AopProxy.java:657)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:608)
at com.xxxxxxxxxxxx.csp.list.SessionProxy$$EnhancerByCGLIB$$3b5c1aae.getPippo(<generated>)
at com.xxxxxxxxxx.csp.realtime.RealtimeListener.onMessage(RealtimeListener.java:91)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:326)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:264)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1071)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1063)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:960)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.springframework.web.context.request.SessionScope.get(SessionScope.java:90)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
... 15 moreMoreover in the same application i have the following bean that inject the same session bean and it works:
Code:
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import java.util.Properties;
import javax.naming.Context;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.xxxxxx.csp.beans.CleanSession;
import com.xxxxxxxx.csp.beans.CustomSession;
import com.xxxxxxx.csp.controller.UserController;
import com.xxxxxx.csp.exceptions.LoginFailedException;
import com.xxxxxx.csp.list.SessionProxy;
import com.xxxxx.csp.realtime.UserSessionId;
import com.xxxxxxx.csp.util.SpringBeans;
import com.xxxxxx.csp.webapi.ifaces.UserManagement;
import com.hazelcast.core.Hazelcast;
public class PPUAuthenticationSuccessHandler implements AuthenticationSuccessHandler, Serializable {
private static final long serialVersionUID = 9186978514071480867L;
protected static Logger logger = Logger.getLogger(PPUAuthenticationSuccessHandler.class);
@Autowired
private SessionProxy sessionProxy;
public SessionProxy getSessionProxy() {
return sessionProxy;
}
public void setSessionProxy(SessionProxy sessionProxy) {
this.sessionProxy = sessionProxy;
}
public void onAuthenticationSuccess(HttpServletRequest req, HttpServletResponse res, Authentication auth) throws IOException, ServletException {
logger.info("Starting login process.....");
SimpleUrlAuthenticationSuccessHandler sas = new SimpleUrlAuthenticationSuccessHandler();
sas.onAuthenticationSuccess(req, res, auth);
try {
logger.info(sessionProxy.getPippo());
} catch (Exception e) {
logger.error("Login failed: " + e);
}
}
}Code:
<bean lazy-init="true" class="com.xxxxx.csp.security.PPUAuthenticationSuccessHandler">
</bean>





