3
我已经开发了一个Spring Web的MVC应用程序作用域bean。我的项目中有一些办公室。每个用户都属于一个办公室。 user.getOfficeType()
返回一个代表用户的办公类型的整数。如果办公室类型为1,用户所属OFFICE1等 不过,我想验证用户的办公注入我的服务类:如何创建一个春季会议基于用户属性
class MyService{
@Autowired
Office currentOffice;
...
}
我读了春天文档。我需要一个会话scoped bean来将它注入到我的服务类中。
的applicationContext.xml:
<mvc:annotation-driven />
<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>
<context:annotation-config />
<context:component-scan base-package="com.package.controller" />
<context:component-scan base-package="com.package.service" />
...
<bean id="office" class="com.package.beans.Office" scope="session">
<aop:scoped-proxy/>
</bean>
我有Office
接口的三种实现。一旦用户请求资源,我想知道他的办公室。所以我需要将他的会话范围的Office注入到我的服务类中。但我不知道如何根据用户的办公室实例化它。请帮忙!
是用户会话bean呢? –
不,它是一个实体。我可以用'SecurityContextHolder.getContext()来访问它。getAuthentication()' –