Announcement Announcement Module
Collapse
No announcement yet.
Session beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Session beans

    Hi,
    i have a question about beans with scope="session".

    I have a service that needs the userProfile bean, this bean contains the user profile () and it is populated at first call with an Interceptor to the login page.

    I would like to wire the userProfile bean to the service bean, but I get this error starting the server: java.lang.IllegalStateException: No thread-bound request found.

    I know can't be a userProfile starting the server, but why it is just null?
    Thank you.

  • #2
    I tried a configuration like this:
    Code:
    <bean id="userProfile" class="com.dsi.lari0.common.dto.UserProfile" scope="session" />
    and also like this:

    Code:
    <bean id="userProfile" class="com.dsi.lari0.common.dto.UserProfile" scope="session" ><aop:scoped-proxy/></bean>
    But it dosen't work (and i get some aop errors)... can you help me please?

    Thank you.

    Comment


    • #3
      I guess using <aop:scoped-proxy/> is the way to go.
      What "aop errors" do you get?

      Comment


      • #4
        This:

        java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

        But i'm sure i included org.springframework.aop-3.0.4.RELEASE.jar

        Comment


        • #5
          It's not in spring-aop.jar (just open the jar and see for yourself), but in aopalliance.jar.
          It's easy to find by doing a findjar.com search (http://www.findjar.com/class/org/aop...op/Advice.html).

          Besides that, you may also need spring-aspects.jar, aspectjrt.jar and aspectjweaver.jar, depending on what Spring AOP features you use.

          Comment


          • #6
            It works!
            Just another question...
            how can I get this session bean directly from the JSP?

            I Tried:
            <c:out value="${sessionScope.userProfile}">
            and
            <c:out value="${scopedTarget.userProfile}">

            but it doesn't work...
            Last edited by Tobia; Oct 18th, 2010, 11:00 AM.

            Comment


            • #7
              That would work if Spring session beans were actually session variables, which they aren't. So you have to explicitely autowire your session bean to the controller and add it to the model, e.g. model.addAttribute("userProfile", userProfile);

              Then you can access it in JSP with <c:out value="${userProfile}">

              Comment


              • #8
                Ok, but I need the userprofile to built all JSP page header, is there any other way to add it to the JSP? Somethink like to add it to the servlet context?

                Thank you.

                Comment


                • #9
                  Then stick to actual session attributes. E.g. if you have a controller method which handles authentication, you can do request.getSession().setAttribute("userProfile", userProfile); and then access it in JSP with <c:out value="${sessionScope.userProfile}">

                  Comment


                  • #10
                    Yes, this is what I will do! Thank you.

                    I think my trouble with my session bean is not end...

                    I have this code in a Interceptor:
                    Code:
                    authService.build();
                    menuService.build();
                    Both services have an autowired field:
                    Code:
                    @Autowired
                    private UserProfile userProfile;
                    While I'm debugging I see that the authService add all values to the userProfile object but in menuService this object is still empty..

                    Comment


                    • #11
                      Mmhh.. maybe this is just a debugger trouble due to proxy...

                      Comment

                      Working...
                      X