1
我的下一個綠豆:會話範圍鑑於豆與Spring 3
@Component
@ComponentScan("es.pys.model")
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Sesion {
private Long id;
private String name;
}
,我使用幾個控制器。
@Autowired
private Sesion sesion;
我希望在我看來太(例如)使用它:
<spring:message code="welcome" arguments="${fn:escapeXml(sesion.name)}" htmlEscape="false"/>
的問題是,前行不起作用,因爲sesion
不存在。
在我所有的觀點中,我如何訪問我的豆,,只有這個豆? 我一直在閱讀解決方案,如:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="exposedContextBeanNames">
<list>
<value>sesion</value>
</list>
</property>
</bean>
的事情是,我需要在applicationContext.xml
來定義,而不是使用說明我的豆腐,還是我錯了?
想法?
謝謝!
不要緊,你的bean是如何定義的(XML,註釋,Java的配置或屬性),只要添加到您的servlet-context.xml的作爲名稱匹配它將被暴露。 –
@ Component組件上的'@ ComponentScan'沒有任何意義,在這個位置也沒有任何意義。 –