I don't know what I am missing, checked all the links which tells about request-scoped bean creation but I am missing something that's why request-scoped bean is not creating.
Here is request scoped bean class:
package com.spring.beans;
public class RequestScopedBean
{
public RequestScopedBean()
{
System.out.println("RequestScopedBean constructor");
}
@Autowired
HttpServletRequest request;
public void getSessionId()
{
if(request != null)
{
System.out.println(request.getSession().getId());
}
}
}
Web.xml
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>com.spring.systemaudit.OESLog4jListener</listener-class>
</listener>
<listener>
<listener-class>se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
</web-app>
and root-context.xml
...
<bean id="requestScopedBean" class="com.spring.beans.RequestScopedBean" scope="request">
</bean>
...
If I make scope="singleton"
then bean is created because I can see sysout
on console while starting server then why not with scope="request"
. What I am missing?