1

私は次の豆を持っています:

@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 にアクセスし、この Bean のみにアクセスするにはどうすればよいですか? 私は次のような解決策を読んできました:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="exposedContextBeanNames">
        <list>
             <value>sesion</value>
        </list>
    </property>
</bean>

問題は、注釈を使用する代わりに Bean を定義する必要があるということapplicationContext.xmlですか、それとも間違っていますか?

アイデア?

ありがとう!。

4

1 に答える 1