Why don't you post you xml config? Is you session bean in session scope? How did you determine that it is injecting in a request scope?
Are you confident that a new session isn't being created for the request? (if user has cookie's disabled and you are not using URL encoding?)
I have mocked the web context to test my controller and there i am creating threads to test this.
i have few confusion also ..
1-As controllers are singleton so if i define any bean to be injected scoped session, will it really be instantiated for each session as there will be only one instance of controller will be created and all the dependencies will be injected at instantiation time only.
2- with aop scoped also the bean will be instantiated for every use not depending on scope defined in xml.
Yes it will. That's what the <aop:scoped-proxy> is designed to do.
I would suggest that you read up this section in the documentation that explains how scoped proxies work.
Joined: Feb 11, 2010
Thanks for the info Sam...
but is there any way i can control the bean injection depending on scope rather then default aop injection.
i thought of using method injection verifying the session from like below
but i want to know is there any way we can configure xml for this behavior.
aop:scoped-proxy is the best cleanest way to get a bean injected into another bean at a different scope. It keeps your code POJO like and clean, you do not have to do anything different to the code whether it was session or request or singleton scope.
The old way before aop:scoped-proxy required you to tightly couple your code to Spring and write extra code. Not good for maintenance, not good for refactoring, just not a good way to do it. But I will tell you that way.
You can have your Controller implement ApplicationContextAware, it has one method setApplicationContext(ApplicationContext context). You assign the context to an instance variable of your controller, and anytime you need that bean that is scoped at session you call context.getBean()
Also, note that you are running tests, which are not in a Web environment. So you mock it out and pretend so that you don't get an exception. So you will have very short lived HttpSessions, so much that they will look exactly like Requests, in my opinion.
Joined: Feb 11, 2010
i verified the same in application and session beans are injected properly..