If we are not allowed to use static variables in the beans session, how do we determine the registrar?

I read from time to time that we should not use static variables in a bean session. Then, how should I get the logger for this bean and use it in all bean methods?

+3
source share
3 answers

I think you interpret the "rule" too strictly.

You cannot store any servlet / session / bean state in a static variable, since this link is shared with all instances of this type.

( ) - . IMO Logger, / :

public class SomeTypeOfBean {
    private static final Logger log = Logger.getLogger(SomeTypeOfBean.class);
    //...
}
+7

( , ), , ( ).

, . ( , ).

, EJB - , , ( ). , , ( , , ). , , , , , .

+3

You can just make it a non-stationary member.

+1
source

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


All Articles