Мне нужен сеансовый компонент, доступный для уровней доступа к службам и данным, но я не хочу вводить его в каждый объект.Статический класс для извлечения сессионного компонента в Spring и JSF
Я не хочу, чтобы это:
<!-- a HTTP Session-scoped bean exposed as a proxy -->
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
<!-- this next element effects the proxying of the surrounding bean -->
<aop:scoped-proxy/>
</bean>
<!-- a singleton-scoped bean injected with a proxy to the above bean -->
<bean id="userService" class="com.foo.SimpleUserService">
<!-- a reference to the proxied 'userPreferences' bean -->
<property name="userPreferences" ref="userPreferences"/>
</bean>
ли создать Возможное статический класс для извлечения компонента сеанса текущего запроса?
Что-то вроде этого:
<!-- a HTTP Session-scoped bean exposed as a proxy -->
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
<!-- this next element effects the proxying of the surrounding bean -->
<aop:scoped-proxy/>
</bean>
Public Class sessionResolver{
public static UserPreferences getUserPreferences(){
//Not real code!!!
return (UserPreferences)WebApplicationContex.getBean("userPreferences")
}
}
Я установил код-макет в getUserPreferences, потому что я думаю, что это невозможно сделать в конфигурации весны, но я предпочитаю конфигурацию вместо кода, конечно. – jlvaquero