Spring-MVC can expose the application context's beans to the view layer, if that is what you wish to do.
For example, the InternalResourceViewResolver
can be instructed to expose every bean in the context, or just specified ones. Take a look at the exposeContextBeansAsAttributes and exposedContextBeanNames properties.
For example, say you wanted to expose the beans beanA
and beanB
to your JSPs. You would declare the view resolver in your context thus:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="exposedContextBeanNames">
<list>
<value>beanA</value>
<value>beanB</value>
</list>
</property>
</bean>
Alternatively, to just expose every bean:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="exposeContextBeansAsAttributes" value="true"/>
</bean>
Whether or not this is a good idea is another question, but Spring does give you the option.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…