Using a Bean Session

The following code returns null:

AController.java

    private MyAppUser getMyAppUser(HttpSession session) {
        MyAppUser myAppUser = (MyAppUser) session.getAttribute("myAppUserManager");
        return myAppUser;
    }

I also tried this:

AController.java

@Autowired
MyAppUser myAppUser;

Despite the fact that in my context, I have the following:

<bean id="myAppUserManager" class="com.myapp.profile.MyAppUser" scope="session"/>

It doesn’t make any sense to me, the "myAppUser" bean is a bean that can absolutely never be null, and I need to be able to refer to it from controllers, I don’t need this in services or repositories, just controllers, but it seems , they are not stored in the session, the precedent is extremely simple, but I could not figure out what happened, or come up with a good workaround

+3
source share
1 answer

beans . Spring , , .

scoped bean, beans, bean. , , - . . , bean A bean A bean B, bean B ( ), scoped-proxies - . , .

+2

Source: https://habr.com/ru/post/1749098/


All Articles